Php 缩略图路径不是';t保存在数据库中
我有一个简单的图像上传代码,在上传时也会创建图像的缩略图。问题是缩略图保存到目录中,但在数据库中未保存缩略图的路径。原始图像的路径已正确保存 这是密码Php 缩略图路径不是';t保存在数据库中,php,laravel,Php,Laravel,我有一个简单的图像上传代码,在上传时也会创建图像的缩略图。问题是缩略图保存到目录中,但在数据库中未保存缩略图的路径。原始图像的路径已正确保存 这是密码 $image = $request->file('image'); if( $image && $image->isValid()){ $imagename = str_random(20).'.'.$image->getClientOriginalExtension();
$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\u thumb=$thumb\u img代码>未保存在数据库中。我还在我的模型中添加了image\u thumb
列filleble
有什么问题吗?您需要先获取$thumb\u img
名称,然后将其保存到数据库列中!比如:$thumb\u img=$destinationPath./thub\u.$imagename代码>不要忘记接受最佳答案!:)您需要先获取$thumb\u img
名称,然后将其保存到DB列中!比如:$thumb\u img=$destinationPath./thub\u.$imagename代码>不要忘记接受最佳答案!:)
$thumb_img = Image::make($image->getRealPath())->resize(200, 200);
$thumb_img->save($destinationPath.'/thub_'.$imagename,80);
$thumb_img = $destinationPath.'/thub_'.$imagename;