正在上传laravel框架中的配置文件图像


Uploading profile image in laravel framework

嗨,我是laravel框架的新手,我正在开发一个仪表板,当用户在仪表板中更新他的详细信息和个人资料照片时,我没有收到任何错误,但当用户只更新细节以保持图像不变(不更新图像)时,我收到一个错误:"在非对象上调用成员函数getClientOriginalName()"

我的blade.php是:

{{ Form::open(array('route' => 'account.profile-update', 'class' => 'form-horizontal', 'files'=>true)) }}
<div class="uploader" id="uniform-file">
                    {{Form::file('fileinput')}}
                    <span class="filename" style="-webkit-user-select: none;">Upload Image</span>
                    <span class="action" style="-webkit-user-select: none;">Browse</span>
                </div>
                <div>Please upload image of size 150x150 pixels</div>
            </div>

我的UserController.php:

public function updateProfile()
{
     $input = Input::all();        
      if ($this->user->updateUser($input)) {
          return Redirect::back()->withMessage('Data saved successfully');
      } else {
         return View::make('error.generic-errors')->withErrors($this->user->getMessages());
      }
 }

my UserRepository.php:

   public function updateUser(array $attributes)
{
    $user = $this->getLoggedUser();
    if (strcmp($user->first_name, $attributes ['first_name']) !== 0)
        $user->first_name = $attributes ['first_name'];
    if (strcmp($user->last_name, $attributes ['last_name']) !== 0)
        $user->last_name = $attributes ['last_name'];
    if (strcmp($user->email, $attributes ['email']) !== 0)
        $user->email = $attributes ['email'];
    $this->updateUserInfo($attributes);
    if ($user->save()) {
        return true;
    } else {
        $this->messageBag->add('update_profile', 'Error while saving user details in profile page');
        return false;
    }
}
 private function updateUserInfo($attributes)
{
    $user_detail = UserDetail::where('user_id', '=', $this->getLoggedUserID())->firstOrFail();
    if (array_key_exists('fileinput', $attributes)) {
        if (!is_null($user_detail->picture)) {
            File::delete(public_path() . $user_detail->picture);
        }
        $user_detail->picture = $this->getImageName($attributes);
    }
    $user_detail->updateIfKeyExists($attributes);
}
   private function getImageName(array $attributes)
{
    if (!array_key_exists('fileinput', $attributes)) {
        return null;
    }
    $file = Input::file('fileinput');
    $destinationPath = public_path().Config::get('far.profile_pic_folder');                                    
    $temp_filename = 't_' . str_random(6) . '_' . substr($file->getClientOriginalName(), -40);
    $new_filename = substr($temp_filename, 2);
    $uploadSuccess = $file->move($destinationPath, $temp_filename);
    //TODO - check and handle for large filesize
    $img = Image::make($destinationPath . $temp_filename)->resize(150, 143)->save($destinationPath . $new_filename);
    File::delete($destinationPath . $temp_filename);
    return Config::get('far.profile_pic_folder') . $new_filename;
}

请帮我解决这个问题。提前感谢

您需要安装在composer.json文件"intervention/image":"~2.0"中添加的包来上传图像。

请参阅此处http://image.intervention.io/getting_started/installation#laravel

您的json文件如下所示。

"require": {
        "laravel/framework": "4.2.*",
        "robclancy/presenter": "1.3.*",
        "intervention/image": "~2.0"
    },

在json文件中添加后。运行composer更新