laravel 4上传文件

时间:2013-07-23 16:01:42

标签: php upload laravel laravel-4

我正在尝试制作一个表单来上传文件,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-&gt; getClientOriginalName()而不是Input :: file('cvs.name'),但我在非对象上调用成员函数getClientOriginalName(),在我看来,表格不正确,而且没有正确收回文件

1 个答案:

答案 0 :(得分:0)

只需调用Input :: file('cvs')一次,第二次调用null对象。

示例:

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

有效。