Skip to content

Commit 2808742

Browse files
committed
Give random name to new images
1 parent 9b5f2da commit 2808742

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

app/Http/Controllers/Api/ProductController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,11 @@ private function saveImages($images, Product $product)
123123
if (!Storage::exists($path)) {
124124
Storage::makeDirectory($path, 0755, true);
125125
}
126-
if (!Storage::putFileAS('public/' . $path, $image, $image->getClientOriginalName())) {
126+
$name = Str::random().'.'.$image->getClientOriginalExtension();
127+
if (!Storage::putFileAS('public/' . $path, $image, $name)) {
127128
throw new \Exception("Unable to save file \"{$image->getClientOriginalName()}\"");
128129
}
129-
$relativePath = $path . '/' . $image->getClientOriginalName();
130+
$relativePath = $path . '/' . $name;
130131

131132
ProductImage::create([
132133
'product_id' => $product->id,

0 commit comments

Comments
 (0)