我有一个问题要获取由noupuploaderbundle上传的文件的原始名称
如果我使用
$this->getRequest()->files[0]->getClientOriginalName();
(请参阅此帖子上传文件的原始名称)我有一个错误:
fatalerrorexception:错误:无法使用 键入Symfony component httpfoundation filebag作为数组 /home/.../uploadlistener.php 第17行
但我认为是正确的,请参阅var_dump:
$request = $event->getRequest();
var_dump($request->files);
给予:
object(SymfonyComponentHttpFoundationFileBag)#11 (1) {
["parameters":protected]=>
array(1) {
["file"]=>
array(1) {
[0]=>
object(SymfonyComponentHttpFoundationFileUploadedFile)#12 (7) {
["test":"SymfonyComponentHttpFoundationFileUploadedFile":private]=>
bool(false)
["originalName":"SymfonyComponentHttpFoundationFileUploadedFile":private]=>
string(22) "silk_icons_preview.png"
["mimeType":"SymfonyComponentHttpFoundationFileUploadedFile":private]=>
string(9) "image/png"
["size":"SymfonyComponentHttpFoundationFileUploadedFile":private]=>
int(116463)
["error":"SymfonyComponentHttpFoundationFileUploadedFile":private]=>
int(0)
["pathName":"SplFileInfo":private]=>
string(14) "/tmp/php3GUXwQ"
["fileName":"SplFileInfo":private]=>
string(9) "php3GUXwQ"
}
}
}
}
谢谢!
您必须这样做:
$this->getRequest()->files->get('file')->getClientOriginalName();
'file'
值是文件输入的名称。
我的功能:
public function onUpload(PostPersistEvent $event) {
$test = $event->getRequest()->files->get('upload')->getClientOriginalName();
var_dump($test);
}
我的表格:
<form action="{{ oneup_uploader_endpoint('gallery') }}" class="dropzone" name="upload" type="file" method="post" id="doc"></form>
做:
fatalerrorexception:错误:致电成员功能 getClientoriginalName()在非对象上 /home/www/.../uploadlistener.php行19