2013-07-23 145 views
0

我試圖做一個表單來上傳文件,Excel文件, 這是我的HTMLlaravel 4上傳文件

<h2>Agregar Torneo</h2> 
{{Form::open('admin/addtorneo', 'POST',array('files' => 'true', 'enctype' => "multipart/form-data"))}} 

    {{Form::label('cvs', 'Archivo:')}} 

    {{Form::file('cvs')}} 

    {{Form::submit('Subir')}} 

{{Form::close()}} 

和PHP

$file = Input::file('cvs'); 

    $destinationPath = 'uploads/'.Str::random(5); 

    $filename = Input::file('cvs.name'); 

    $uploadSuccess = Input::file('cvs')->move($destinationPath, $filename); 

    $new = new Torneo; 

    $new->nombre = $filename; 
    $new->dir = $destinationPath; 

    $new->save(); 

    return "Torneo agregado <br> <a href='../admin'>Volver</a>"; 

,但我一直越來越

Call to a member function move() on a non-object 

我使用文件 - $> getClientOriginalName(),而不是輸入::文件試圖(「cvs.name」),但我得到調用一個成員函數getCl ientOriginalName()在一個非對象上,在我看來,表單是不正確的,它不是正確地reciving該文件

+0

看起來像$ filename沒有被生成。將$ filename更改爲'testname'(沒有它作爲變量),看看是否解決了這個問題。基本上它看起來像$ filename ='test';如果確實有效,那麼將文件名改爲:$ filename = $ file ['name']; – OffTheFitz

+0

我一直在調用成員函數move()在非對象上:/ – JoseMiguel

+0

當你在html中查看錶單時,你看到了什麼?也許你沒有設置一個'名字'就是id。 – OffTheFitz

回答

0

只需調用輸入::文件('cvs')一次,第二次它變成空對象。

例如:

$file = Input::file('cvs'); 
$destinationPath = 'uploads/'.Str::random(5); 
$file->move($destinationPath); 

它的工作原理。