我有简单的图像上传代码,在上传时也创建了图像的缩略图。问题是将缩略图保存到目录中,但在数据库中并不能保存到缩略图的路径。正确保存原始图像的路径。
这是代码
$image = $request->file('image');
if( $image && $image->isValid()){
$imagename = str_random(20).'.'.$image->getClientOriginalExtension();
$destinationPath = public_path('/uploads');
$thumb_img = Image::make($image->getRealPath())->resize(200, 200);
$thumb_img->save($destinationPath.'/thub_'.$imagename,80);
$destinationPath = public_path('/uploads');
$image->move($destinationPath, $imagename);
}
$item->image = $imagename;
$item->image_thumb = $thumb_img;
因此,$item->image_thumb = $thumb_img;
没有保存在数据库中。我也在型号中的fillable
中添加了image_thumb
列。
有什么问题?
$thumb_img = Image::make($image->getRealPath())->resize(200, 200);
$thumb_img->save($destinationPath.'/thub_'.$imagename,80);
$thumb_img = $destinationPath.'/thub_'.$imagename;