我已经从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
答案 0 :(得分:0)
您必须将绝对路径传递给模型关系。
来自docs:
您还可以将字符串传递给包含 本地文件的绝对路径。
$model->avatar = Input::file('file_input');
所以在您的情况下:
$user->avatar = Storage::get('public/profile_images/'. $filenametostore);