我在图片更新方面遇到了一个奇怪的问题。添加新产品后,我需要选择更新图像并在插入时出现此错误一切正常。
getimagesize(2.png): failed to open stream: No such file or directory
这是我的代码
$file = $request->image;
if (isset($file))
{
list($width, $height) = getimagesize($file);
$extension = $file->getClientOriginalExtension();
$final_filename = $file->getFilename() . '.' . $extension;
$new_height_75 = (75 * $height) / $width;
$thumb_img_75 = Image::make($file->getRealPath())->resize(75, $new_height_75);
$thumb_img_75->save(public_path('attachments/product_images/thumbs_75').'/'.$final_filename,80);
$new_height_250 = (250 * $height) / $width;
$thumb_img_250 = Image::make($file->getRealPath())->resize(250, $new_height_250);
$thumb_img_250->save(public_path('attachments/product_images/thumbs_250').'/'.$final_filename,80);
$new_height_150 = (150 * $height) / $width;
$thumb_img_150 = Image::make($file->getRealPath())->resize(150, $new_height_150);
$thumb_img_150->save(public_path('attachments/product_images/thumbs_150').'/'.$final_filename,80);
Storage::disk('product_images')->put($final_filename, File::get($file));
$product->image = $final_filename;
}
如果我dd($ file);它获取我要上传的文件。 感谢
答案 0 :(得分:0)
为什么不尝试使用laravel验证器来验证图像类型以及图像文件大小https://laravel.com/docs/5.4/validation#rule-image