ошибка octobercms: аватар должен быть изображением

Я изменил размер аватара пользователя intervention image на странице account.php из плагина rainlab / user я пытаюсь сохранить его в базе данных 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

0

Решение

Вы должны пройти абсолютный путь к модельным отношениям.

От документы:

Вы также можете передать строку в атрибут данных, который содержит
абсолютный путь к локальному файлу.

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

Итак, в вашем случае:

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

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector