hasFile函数在laravel 5.4中不起作用

时间:2017-04-28 19:19:54

标签: php laravel-5.4

我正在尝试使用Image Intervention Package上传照片 我试过dd($ request-> hasFile(' avator'))并返回false 我回来了#34;错误"在我的if语句中只是为了确保我有错误 提前致谢

public function update_photo(Request $request){ 
    if($request->hasFile('avator') ){
        $avator = $request->file('avator');
        $filename = time() . '.' . $pic->getClientOriginalExtension();
        Image::make($avator)->resize(300 , 300)->save(public_path('/uploads/avators' . $filename));
        $user = Auth::user();
        $user->avator = $filename ; 
        $user->save();
        echo "hello world !";
    }else {
        echo " Error"; // just to make sure that i have an error
    }
    return view("profile" , array("user" => Auth::user() ));

}

2 个答案:

答案 0 :(得分:0)

首先编辑此行代码

$filename = time() . '.' . $avator->getClientOriginalExtension();

也添加到此斜杠

Image::make($avator)->resize(300 , 300)->save(public_path('/uploads/avators/' . $filename));

*在你的刀片模板中确保拼写你正在写avator而不是头像*

<input type="file" name="avator"/>

答案 1 :(得分:0)

在刀片中将其放入表单标签:

enctype="multipart/form-data

并在您的控制器中:

use File;