简体   繁体   English

无法在Laravel 5.2中使用干预图像上传图像

[英]Cannot upload image with Intervention image in Laravel 5.2

I am trying to upload an image using the tutorial here . 我正在尝试使用此处的教程上传图像。 I have followed the instructions exactly as in the video, but once I click on the submit button, it brings me back to the profile page, and the image is unchanged, nothing has changed in the database or uploaded to the folder designated. 我完全按照视频中的说明操作,但是一旦我点击提交按钮,它就会将我带回到个人资料页面,图像没有变化,数据库中没有任何变化或上传到指定的文件夹。

Here is my routes.php : 这是我的routes.php

Route::get('profile', 'UserController@showProfile');
Route::post('profile', 'UserController@updateAvatar');

Here is the blade file: 这是刀片文件:

<div class="row">
   <div class="col-sm-4">
       <div class="text-align-center">
           <img class="img-circle" src="/uploads/avatars/{{ Auth::user()->avatar }}" alt="64x64" style="height: 112px; border-radius:50%;">
       </div>
       <br>
       <br>
       <div class="text-align-center">
          <form enctype="multipart/form-data" action="{{ url('/profile') }}" method="POST">
          <h5>Update Profile Image</h5>
          <input type="file" name="avatar">
          <input type="hidden" name="_token" value="{{ csrf_token() }}"> <br>          
          <input type="submit" class="pull-left btn btn-sm btn-primary">
          </form>
       </div>
</div>

Here is the controller: 这是控制器:

 public function showProfile(){

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

    public function updateAvatar(Request $request){
        //Handle the user upload of avatar
        if($request->hasFile('avatar')){
            $avatar = $request->file('avatar');
            $filename = time() . '.' . $avatar->getClientOriginalExtension();
            Image::make($avatar)->resize(200, 200)->save( public_path('/uploads/avatars/' . $filename ) );
            $user = Auth::user();
            $user->avatar = $filename;
            File::
            $user->save();
        }

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

I have added a field avatar to the users table. 我在users表中添加了一个字段avatar

public function update_avatar(Request $request){

    // Handle the user upload of avatar
    if($request->hasFile('avatar')){
        $avatar = $request->file('avatar');
        $filename = time() . '.' . $avatar->getClientOriginalExtension();
        $avatar->move('/uploads/avatars', $filename);       
        $user = Auth::user();
        $user->avatar = $filename;
        $user->save();
    }

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

}

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

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