Reputation: 343
I'm trying to save an image that is coming from my request in my storage, but something strange is happening: I have the following code
$ request-> file ('UploadIMG') -> store ('public'. '/'. 'clients');
when it is executed it saves the image in the following location
storage \ app \ public \ clients \ dUpBTL0V25h2Q1825IUmvvIZhcwVPixLaVDdItuG.jpg
I wanted to change this value and set a name, so I used the following code
Storage :: disk ('local') -> put ('clients'.'/'.$ fileName, $Image, 'public');
let's say my $ fileName has the value of 01.jpg when I run that storage it creates
storage \ app \ clients \ 01.jpg \ dUpBTL0V25h2Q1825IUmvvIZhcwVPixLaVDdItuG.jpg
it ends up creating a folder with the name of the image and places the image with the random name, how do I get a name for my image?
Upvotes: 1
Views: 7429
Reputation: 2469
$file = $request->file('pic');
$picName = $file->getClientOriginalName();
$imagePath = '/public/clients';
$file->move(public_path($imagePath), $picName);
Upvotes: 1
Reputation: 163788
You can use the storeAs()
method to save uploded file and name it:
$request->file('UploadIMG')->storeAs('public/clients', $fileName);
Upvotes: 2