$request = $event->getRequest();
print_r($request->files);die;
gives me
Symfony\\Component\\HttpFoundation\\FileBag Object
(
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.
I'm using symfony 4,
I wanted to get the files original name. What worked for me is:
$form = $this->createForm(SomeType::class, $object);
if($form->isSubmitted() && $form->isValid()) {
$fileName = $object->getImage()->getClientOriginalName();
}
In my case getImage() is the getter for the name of the file upload field. So that would change to your relevant getter function for the file upload field.
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
This wound up working for me, I guess the OneUp Class handles it a bit differently
use Oneup\UploaderBundle\Event\PostPersistEvent;
class UploadListener
{
public function onUpload(PostPersistEvent $event)
{
$request = $event->getRequest();
$original_filename = $request->files->get('blueimp')->getClientOriginalName();
}
}
Relevent Frontend
<input id="fileupload" type="file" name="blueimp" data-url="{{ oneup_uploader_endpoint('images') }}" multiple />