$request = $event->getRequest();
print_r($request->files);die;
gives me
Symfony\Component\HttpFoundation\FileBag Object
(
[parameters:protected] => Array
(
[files] => Array
(
[0] => Symfony\Component\HttpFoundation\File\UploadedFile Object
(
[test:Symfony\Component\HttpFoundation\File\UploadedFile:private] =>
[originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => Chrysanthemum.jpg
[mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => image/jpeg
[size:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 879394
[error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0
[pathName:SplFileInfo:private] => /tmp/phpmUl54W
[fileName:SplFileInfo:private] => phpmUl54W
)
)
)
)
I'm trying to get at the value for 'originalname' i.e "Chrysanthemum.jpg" without resorting to a loop, but I can't seem to find the right syntax
Using the 1UP file uploader, but I dont think that's important
Try document. getElementById("FileUpload1"). value this value should have a path for a file to be uploaded, just strip all dirs from that value and you will have file name.
In PHP, we can access the actual name of the file which we are uploading by keyword $_FILES[“file”][“name”]. The $_FILES is the by default keyword in PHP to access the details of files that we uploaded. The file refers to the name which is defined in the “index. html” form in the input of the file.
The hashName method is exactly what Laravel calls in the store method. $request->image->hashName(); You will get the same name that Laravel generates when it creates the file name during the store method. $path = $request->image->getClientOriginalName();
When you upload files you get UploadFile
(API link) objects (basically the wrappers of array).
$this->getRequest()->files[0]->getClientOriginalName();
Can't try this now but you might need to do this instead:
$this->getRequest()->files['name_of_file_field_in_post']->getClientOriginalName();
where you would replace name_of_file_field_in_post
with your form field's name.
2015 Update:
$request->files->get('your-file-name')->getClientOriginalName();
your-file-name
for me was just file
.
This will probably help too: https://github.com/1up-lab/OneupUploaderBundle/issues/21
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With