0

我正在尝试制作一个表格来上传文件,一个excel文件,这是我的html

<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

我尝试使用 $file->getClientOriginalName() 而不是 Input::file('cvs.name') 但我在非对象上调用成员函数 getClientOriginalName(),在我看来,表单不是对,它没有正确接收文件

4

1 回答 1

0

Just call Input::file('cvs') one time, the second time it becomes null object.

example :

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

It works.

于 2013-12-06T02:55:11.223 回答