使用干预图像调整用户头像的大小后,我尝试将其存储在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 :(得分:0)
您只是在设置文件名,应该在此处设置图片的完整路径。
假设您已经在用户模型中拥有
avatar
个附件关系
public $attachOne = [
'avatar' => ['System\Models\File']
];
替换
$user->avatar = $filenametostore;
与
$user->avatar = storage_path($thumbnailpath);
也许应该有用。
如有疑问,请发表评论。