【问题标题】:error octobercms:The avatar must be an imageerror octobercms:头像必须是图片
【发布时间】:2018-10-26 14:01:36
【问题描述】:

我在rainlab/user 插件的account.php 页面中使用intervention image 调整了用户头像的大小,我尝试将其存储在octobercms 数据库中,如下代码:

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;
}

我收到此错误:

The avatar must be an image.
C:\wamp643\www\october3\vendor\october\rain\src\Database\Traits\Validation.php line 340

【问题讨论】:

    标签: php laravel octobercms avatar


    【解决方案1】:

    您必须将绝对路径传递给模型关系。

    来自docs

    您也可以将字符串传递给包含 本地文件的绝对路径。

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

    所以在你的情况下:

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

    【讨论】:

      猜你喜欢
      • 2015-09-03
      • 2021-09-26
      • 2016-07-04
      • 2018-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-12
      • 2018-07-13
      相关资源
      最近更新 更多