Laravel Storage copy not working, how to copy a file using storage disk

8.3k Views Asked by At

my following command works fine

copy($file_date['file_name_tmp_target'], $file_date['file_name_target']);

but when i do

\Storage::copy($file_date['file_name_tmp_target'], $file_date['file_name_target']);

or

\Storage::move($file_date['file_name_tmp_target'], $file_date['file_name_target']);

it give me an error following

(1/1) FileNotFoundException File not found at path: Library/WebServer/Documents/project_name/public/report_tmp.csv

any idea? how to just copy file using Storage disk ?

2

There are 2 best solutions below

5
On BEST ANSWER

You should make sure you set your disk in valid way. Storage is using config/filesystems.php and by default uses local disk which is configured like this:

'local' => [
    'driver' => 'local',
    'root' => storage_path('app'),
],

so the file path you pass here should be located in storage/app directory.

0
On

Actually i was doing wrong

This should be the answer, addition to Marcin Answer thanks :)

 \Storage::disk('outdoor_real_time_report_path')->copy($file_date['file_name_tmp'], $file_date['file_name']);