【发布时间】: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