【发布时间】:2018-05-23 05:33:35
【问题描述】:
我的产品有 3 个图像字段,保存方法一切正常,但更新方法 first image 将临时文件保存在数据库中,其他两个更新没有问题。
代码
我在这里分享我所有 3 张图片的更新方法:
//saves temp file instead of file name
if ($request->hasFile('imageOne')) {
$imageOne = $request->file('imageOne');
$filename = 'productone' . '-' . time() . '.' . $imageOne->getClientOriginalExtension();
$location = storage_path('app/public/images/' . $filename);
Image::make($imageOne)->resize(1200, 600)->save($location);
if(!empty($product->imageOne)){
Storage::delete('images/' . $product->imageOne);
}
$product->imageOne = $imageOne;
}
//works with no issue
if ($request->hasFile('imageTwo')) {
$imageTwo = $request->file('imageTwo');
$filename = 'producttwo' . '-' . time() . '.' . $imageTwo->getClientOriginalExtension();
$location = storage_path('app/public/images/' . $filename);
Image::make($imageTwo)->resize(1200, 600)->save($location);
if(!empty($product->imageTwo)){
Storage::delete('images/' . $product->imageTwo);
}
$product->imageTwo = $filename;
}
//works with no issue
if ($request->hasFile('imageThree')) {
$imageThree = $request->file('imageThree');
$filename = 'productthree' . '-' . time() . '.' . $imageThree->getClientOriginalExtension();
$location = storage_path('app/public/images/' . $filename);
Image::make($imageThree)->resize(1200, 600)->save($location);
if(!empty($product->imageThree)){
Storage::delete('images/' . $product->imageThree);
}
$product->imageThree = $filename;
}
有什么想法吗?
【问题讨论】:
标签: laravel