moses toh
moses toh

Reputation: 13162

How can I set path to save image uploaded? Laravel 5.3

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

Answers (2)

Sandeesh
Sandeesh

Reputation: 11906

Use storage_path.

private function addPhoto(UploadedFile $photo, $fileName)
{
    $photo->move(storage_path('temp'), $fileName);
}

Upvotes: 1

Jerodev
Jerodev

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

Related Questions