2015-05-05 46 views
1

我有一個問題讓上傳byoneupuploaderbundle獲取文件

如果我使用

$this->getRequest()->files[0]->getClientOriginalName(); 

(看到這個職位Get Uploaded File's Original Name)文件的原單名 的原始名稱我有這樣的錯誤:

FatalErrorException: Error: Cannot use object of type Symfony\Component\HttpFoundation\FileBag as array in /home/.../UploadListener.php line 17

,但我認爲是正確的,看到的var_dump:

$request = $event->getRequest(); 
var_dump($request->files); 

給:

object(Symfony\Component\HttpFoundation\FileBag)#11 (1) { 
    ["parameters":protected]=> 
    array(1) { 
    ["file"]=> 
    array(1) { 
     [0]=> 
     object(Symfony\Component\HttpFoundation\File\UploadedFile)#12 (7) { 
     ["test":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> 
     bool(false) 
     ["originalName":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> 
     string(22) "silk_icons_preview.png" 
     ["mimeType":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> 
     string(9) "image/png" 
     ["size":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> 
     int(116463) 
     ["error":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> 
     int(0) 
     ["pathName":"SplFileInfo":private]=> 
     string(14) "/tmp/php3GUXwQ" 
     ["fileName":"SplFileInfo":private]=> 
     string(9) "php3GUXwQ" 
     } 
    } 
    } 
} 

謝謝!

+0

$請求 - >文件這是不是喜歡你的var_dump數組告知:Symfony的\組件\ HttpFoundation \ FileBag – MouradK

回答

2

你要做的是:

$this->getRequest()->files->get('file')->getClientOriginalName(); 

'file'值是您的文件輸入名稱。

0

我的功能:

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: Error: Call to a member function getClientOriginalName() on a non-object in /home/www/.../UploadListener.php line 19