0

I have something like that :

In my controller , I wrote this line :

dd($file->path);

and here is result :

UploadedFile {#294
  -test: false
  -originalName: "photo.png"
  -mimeType: "image/png"
  -size: 319216
  -error: 0
  path: "/tmp"
  basename: "phpLJA6Ge"
  pathname: "/tmp/phpLJA6Ge"
}

I want to return .png . How to retrieve originalName?

1 Answer 1

2

To get the name of the file with extension included: $file->getClientOriginalName()

To get the content: file_get_contents($file->getRealPath());

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your comment . If file name is something like this.is.file.png , how to retrieve "png"? I use explode('.',$file->getClientOriginalName()) but it return "this"
Sorry for the late response. If you explode on the ., it will return an array of multiple strings (because you have multiple dots in the file name). To get an extension, you always have to get the last in the array: end(explode('.',$file->getClientOriginalName())).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.