dongrenzheng1619 2016-08-31 13:14
浏览 40
已采纳

无法使用Form Facade在Laravel 5.2中上传图像

I have been struggling to upload an image using a simple form. Every time I upload the file, it says there is no file, as per the functionality I've set up in the controller. Here is the code so far:

The blade form:

 <div class="text-align-center">
    {{Form::open(['url' => 'profile', 'files' => true]) }}
    {{Form::file('avatar')}}
    {{Form::submit('Update',['class' => 'pull-left btn btn-sm btn-primary']) }}
    {{Form::close() }}
</div>

The routes file:

Route::get('profile', 'UserController@profile');
Route::post('profile', 'UserController@avatar');
Route::resource('users','UserController');

The UserController:

public function profile(){

            return view('profile', array('user' => Auth::user()));
    }   

    public function avatar(Request $request){

        if($request->hasFile('avatar')){
                var_dump($request);
        }
        else
                die('there is no file here!');
}

The User model:

protected $fillable = [
        'username', 'email', 'avatar'
    ];

My php.ini has maximum file size limits of 8M, the file I'm trying to upload is only a few KB.

  • 写回答

1条回答 默认 最新

  • dongxiao9583 2016-09-01 09:17
    关注

    I had not cleared the views cache in a long while. This goes to show that the cache could impede new forms from being added. It was still loading the view with two forms, one of which I had already deleted. Once I cleared the view cache with view:clear, and then made a new view with the same code and file name, it was all working then.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?