我正在使用laravel 5.1
,我尝试通过表单上传文件并转到文件夹images / user / id用户,我尝试这样做:< / p>
查看
<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>
我的控制器
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');
}
}
路线
Route::post('account/update/avatar', 'UserController@updateAvatar');
实际上它返回 - &gt;
return redirect('account')->with('message-error', 'File error');
答案 0 :(得分:0)
尝试在输入中添加名称
<input id="input-upload-img1" type="file" class="file" data-preview-file-type="text" name="image">
答案 1 :(得分:0)
<input id="input-upload-img1" type="file" name="image" class="file" data-preview-file-type="text">