dongpai1942 2018-10-26 14:01
浏览 50

error octobercms:头像必须是图像

I have resized the user avatar with intervention image in account.php page from rainlab/user plugin ,i try to store it in the octobercms database like this code:

if (Input::hasFile('avatar')) {
    $file = Input::file('avatar');
    $filenamewithextension = $file->getClientOriginalName();

    //get filename without extension
    $filename = pathinfo($filenamewithextension, PATHINFO_FILENAME);

    //get file extension
    $extension = $file->getClientOriginalExtension();

    //filename to store
    $filenametostore = $filename.'_'.time().'.'.$extension;

    Storage::put('public/profile_images/'. $filenametostore, fopen($file, 'r+'));
    Storage::put('public/profile_images/thumbnail/'. $filenametostore, fopen($file, 'r+'));

    //Resize image here
    $thumbnailpath ='storage/app/public/profile_images/thumbnail/'.$filenametostore;

    $img = Image::make($file->getRealPath());
    $img->crop(request('w'), request('h'), request('x1'), request('y1'));
    $img->save($thumbnailpath);
    $user->avatar = $filenametostore;
}

I get this error:

The avatar must be an image.
C:\wamp643\www\october3\vendor\octoberain\src\Database\Traits\Validation.php line 340
  • 写回答

1条回答 默认 最新

  • duanlan2003 2018-10-26 14:55
    关注

    You have to pass the absolute path to the model relationship.

    From the docs:

    You may also pass a string to the data attribute that contains an absolute path to a local file.

    $model->avatar = Input::file('file_input');
    

    So in your case:

    $user->avatar = Storage::get('public/profile_images/'. $filenametostore);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端