使用图像干预包调整图像大小后,将图像存储在 October CMS 数据库中
Store an image in October CMS database after resizing it with image intervention package
我尝试在使用干预图像包调整大小后将用户头像存储在 October CMS 数据库中我使用此代码:
if (Input::hasFile('avatar')) {
$file= $user->avatar;
$filenamewithextension = $file->getClientOriginalName();
//get filename without extension
$filename = pathinfo($filenamewithextension, PATHINFO_FILENAME);
//get file extension
$extension = $file->getClientOriginalExtension();
//filename to store
$filenametostore = $filename.'_'.uniqid().'.'.$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;
}
但我得到一个错误:
Call to undefined method October\Rain\Database\QueryBuilder::getClientOriginalName()
有人能帮帮我吗?!
您在错误的对象上调用了 getClientOriginalName(),请尝试将代码中的以下行更改为:
if (Input::hasFile('avatar')) {
$file = Input::file('avatar');
/* ... */
Storage::put('public/profile_images/'. $filenametostore, fopen($file->getRealPath(), 'r+'));
Storage::put('public/profile_images/thumbnail/'. $filenametostore, fopen($file->getRealPath(), 'r+'));
/* ... */
}
我尝试在使用干预图像包调整大小后将用户头像存储在 October CMS 数据库中我使用此代码:
if (Input::hasFile('avatar')) {
$file= $user->avatar;
$filenamewithextension = $file->getClientOriginalName();
//get filename without extension
$filename = pathinfo($filenamewithextension, PATHINFO_FILENAME);
//get file extension
$extension = $file->getClientOriginalExtension();
//filename to store
$filenametostore = $filename.'_'.uniqid().'.'.$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;
}
但我得到一个错误:
Call to undefined method October\Rain\Database\QueryBuilder::getClientOriginalName()
有人能帮帮我吗?!
您在错误的对象上调用了 getClientOriginalName(),请尝试将代码中的以下行更改为:
if (Input::hasFile('avatar')) {
$file = Input::file('avatar');
/* ... */
Storage::put('public/profile_images/'. $filenametostore, fopen($file->getRealPath(), 'r+'));
Storage::put('public/profile_images/thumbnail/'. $filenametostore, fopen($file->getRealPath(), 'r+'));
/* ... */
}