Reputation: 13162
My method to upload file in laravel like this :
private function addPhoto(UploadedFile $photo, $fileName)
{
dd(public_path() . DIRECTORY_SEPARATOR . 'img');
$destinationPath = public_path() . DIRECTORY_SEPARATOR . 'img';
$photo->move($destinationPath, $fileName);
}
The result of dd(public_path() . DIRECTORY_SEPARATOR . 'img');
like this :
C:\xampp\htdocs\myshop\public\img
But I want to change it
So, I want to save image uploaded in here :
C:\xampp\htdocs\myshop\storage\temp
How can I save the image in storage folder?
Upvotes: 1
Views: 894
Reputation: 11906
Use storage_path
.
private function addPhoto(UploadedFile $photo, $fileName)
{
$photo->move(storage_path('temp'), $fileName);
}
Upvotes: 1
Reputation: 33186
You can use the exact same way, but replace public_path()
with storage_path()
. This will link to the storage folder for this application.
$destinationPath = storage_path() . DIRECTORY_SEPARATOR . 'temp';
All path helpers can be found in the Laravel documentation.
Upvotes: 2