user9107942
user9107942

Reputation:

How to move uploaded files to public folder inside the public_html in Laravel?

I have a laravel website up and running but I am facing the file uploading issue.I am using the move function to move my uploaded files to my public folder. It is working fine in my Xampp but as I uploaded the website to my server it is not working anymore because the public folder is now inside the public_html. Any help with that??

Upvotes: 0

Views: 3124

Answers (1)

Jinandra Gupta
Jinandra Gupta

Reputation: 545

Destination where you want to move you file

 $destinationPath = 'img';

Image new name

$imageName = 'img_' . rand(1000000, 9999999) . '.' . $request->file('file_name')->getClientOriginalExtension(); //$product->id . '.' .$request->file('file_name')->getClientOriginalExtension();

Move file

$request->file('file_name')->move($destinationPath, $imageName);

File path

$path = public_path() . '/' . $destinationPath . '/' . $imageName;

Upvotes: 1

Related Questions