Search code examples
phplaravellaravel-5.4laravel-filesystemlaravel-storage

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


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 ?


Solution

  • 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.