tiagomatosweb's avatar

Storing and moving file

Hi all, new in Laravel!

I'm using Laravel File System to store locally files that have been uploaded. My logic is when the file is uploaded it goes to a temporary folder. Then, when the whole data is saved I move these files to the correct and public folder.

Currently, I'm using Storage::putFileAs() to store locally which is /storage/public/myfolder/myfiles for example.

Afterwards, I need to move this file to /public/fotos/users for example.

So, I have tried to use Storage::move($oldPath, $newPath), but the new path is always inside the /storage folder not in public.

How I would move the files from storage folder to public?

I would appreciate also if you have any better approach for this scenario.

Tks

0 likes
2 replies
Hujjat's avatar

Here is what you should do

'''

  $photoName = time().'.'.$request->my_photo->getClientOriginalExtension();
    $request->my_photo->move(public_path('user-photos'), $photoName);   

'''

It will give unique name for each photo. You can store the $photoName in database .

Please or to participate in this conversation.