简体   繁体   English

Laravel 5.2-错误上传和存储文件

[英]Laravel 5.2 - Error Upload and store file

I'm working with laravel 5.1 , I'm trying to upload a file by my form and move to folder images/user/id user, I'm trying like this: 我正在使用laravel 5.1 ,正在尝试通过表单上传文件并移至文件夹images / user / id用户,我试图这样做:

VIEW 视图

<form method="post" action="{{url('account/update/avatar')}}" enctype="multipart/form-data" class="form-horizontal" role="form">
    {csrf_field()}}
     <input id="input-upload-img1" type="file" class="file" data-preview-file-type="text">
     <button type="submit" class="btn btn-success">Cambia</button>
</form>

MY CONTROLLER 我的控制器

public function updateAvatar(Request $request){        
    if ($request->hasFile('image')){             
        $username = Auth::user()->id . '.' . $request->file('image')->getClientOriginalExtension();
        $request->file('image')->move('images/users/', $username);
        $user = new User;
        $user->where('email', '=', Auth::user()->email)
                  ->update(['image' => 'images/users/'.$username]);
            return redirect('account')->with('message-success', 'success!');        
    }else{
            return redirect('account')->with('message-error', 'File error');
    }
}

ROUTES 路线

Route::post('account/update/avatar', 'UserController@updateAvatar');

Actually it return --> 实际上它返回->

return redirect('account')->with('message-error', 'File error');

尝试在输入中添加名称

<input id="input-upload-img1" type="file" class="file" data-preview-file-type="text" name="image">
<input id="input-upload-img1" type="file" name="image" class="file" data-preview-file-type="text">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM