文件无法在laravel中上传

问题描述 投票:1回答:4

这是我的路线文件

Route::resource('item', 'ItemController');

Route::get('welcome', function() {
    return view('welcome');
});
Route::auth();

Route::get('/home', 'HomeController@index');
Route::get('/item', 'ItemController@store');

//Route
Route::post('/item', ['as' => 'item.store', 'uses' => 'ItemController@store']);

这是我的商店控制器

public function store(Requests\CreateItem $request)
{
    Item::create($request->all());
    $file = $request->file('filename');
    if (Input::hasFile('filename')) {
        echo 'Uploaded';
        $file = Input::file('filename');
        $file->move('uploads', $file->getClientOriginalName());
    }
}

我的上传表单不会返回任何错误,但这段代码不会将我的上传内容移动到指定的文件夹。我究竟做错了什么?我正在使用Laravel 5.2。

编辑:这是我的表格

   {!! Form::open(['url' =>'route' => 'item.store', 'files' => true]) !!}
    {!! Form::label('name', "Name") !!}
    {!! Form::text('name', null, ['class' => 'form-control']) !!}

   {!! Form::label('filename', "File Name") !!}
    {!! Form::file('filename', null, ['class' => 'form-control']) !!}

    {!! Form::label('description', 'Description') !!}
    {!! Form::textarea('description', null, ['class' => 'form-control']) !!}
    {!! Form::submit('Add Item', ['class' => 'btn btn-primary form-control']) !!}

编辑2:现在我在访问表单时收到以下错误

41b177cdb949fd0263185e364012b35dff81db06.php第7行中的FatalErrorException:语法错误,意外'=>'(T_DOUBLE_ARROW),期待']'

编辑2现在,每当我尝试访问添加项目表单时,我都会收到此错误:

41b177cdb949fd0263185e364012b35dff81db06.php第7行中的FatalErrorException:语法错误,意外'=>'(T_DOUBLE_ARROW),期待']'

php laravel-5.2
4个回答
1
投票

另一个原因是PHP最大上传大小。增加价值,然后再试一次。


0
投票

<form>上有enctype="multipart/form-data"吗?它需要这个来正确发送文件。当<form>中有<input type="file">元素时,它实际上是一个错误,但没有那个属性。

这是一个非常常见的错误,让人们随时都可以。


0
投票

你忘记了昏迷和钥匙

{!! Form::open(['url' =>'route' **, 'key'** => 'item.store', 'files' => true]) !!}

你应该使用url或route,但不能同时使用两者。

{!! Form::open(['route' => 'item.store', 'files' => true]) !!}

0
投票

如果一切正常,那么你需要检查你的文件。使用较小尺寸的其他文件测试上传。

对我来说,当我调整图像大小时它就解决了。

© www.soinside.com 2019 - 2024. All rights reserved.