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.

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

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)