-2

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 ?

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
Muhammad
  • 3,169
  • 5
  • 41
  • 70

2 Answers2

2

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.

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
  • I tried this too Storage::disk('outdoor_real_time_report_path')->copy('old','new') its same error – Muhammad Sep 27 '18 at 18:08
  • And what is `outdoor_real_time_report_path` - how you defined it in `config/filesystems.php`? – Marcin Nabiałek Sep 27 '18 at 18:11
  • how to get rid of this error ?File already exists at path: outdoor_hold_report.csv i dont want this? – Muhammad Sep 27 '18 at 18:12
  • no i can't delete and then copy the file. because file size is like 400 mb what if i delete the file and copy take time and meanwhile user clicks to download the file, he will face error, any better solution ? – Muhammad Sep 27 '18 at 18:25
  • If you just copy file on local filesystem it shouldn't take much time. However if you think it's a problem you need to create solution that would be best in your case. For example you could track each download start/end, save the new file with some other name and then in cron delete old file and put there new one when you are sure file is not downloaded. You also don't need to use exact same name for new file, so you can create new links on site and remove old files/records after some reasonable time (for example you assume downloading takes max 1h and after 1h you delete old files) – Marcin Nabiałek Sep 27 '18 at 18:33
1

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']);
Muhammad
  • 3,169
  • 5
  • 41
  • 70