I'm using the latest version of laravel and when I try to upload an image, the image gets moved to the specified directory but the function returns a error saying temp/some-code does not exist or might have been moved.
try {
foreach ($request->allFiles('product_image') as $productImage) {
foreach ($productImage as $key) {
//parse the file and upload it to a new directory while saving it...
//The images are stored as a json string to the database...
$productImageName = $key->getClientOriginalName();
$productImageExtension = $key->getClientOriginalExtension();
//make an attempt to rename the resource...
$productImageNameArr = explode('.', $productImageName);
array_pop($productImageNameArr);
$newProductImageName = implode('_', $productImageNameArr) . time() . '.' . $productImageExtension;
//move the resource...
$key->move("images/products", $newProductImageName);
array_push($images_images, "images/products/" . $newProductImageName);
}
}
} catch (Exception $e) {
dd($e, 'Fail one Default');
//Bail in case of an error.... and clear the images created before the erro...
foreach ($images_images as $image) {
if (File::exists($image)) {
File::delete($image);
}
} //all images created during the operation has been deleted...
return redirect()->back()->with('error', 'Sorry... An unexpected error occurred and the operation could not be completed. Please, try again later...');
}