Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying a file using 2 disks with Laravel

Tags:

I have 2 disks in Laravel.

One is the local disk, the other one is a FTP server which I need to upload my files to. They are both correctly configured.

I have attempted it this way:

 Storage::disk('FTP')->copy('old/file1.jpg', 'new/file1.jpg');

This would only copy the file if it is already in the FTP server. I have also read the documentation and there seems to be no way to combine both in order to upload files.

Any suggestions?

like image 425
prgrm Avatar asked Nov 30 '17 20:11

prgrm


1 Answers

@ceejayoz has a good answer, but as mentioned in the comments, this fetches, and then writes.

In order to use streams, the following can be used instead:

Storage::disk('FTP')->writeStream('new/file1.jpg', Storage::readStream('old/file1.jpg'));
like image 142
Dan Jones Avatar answered Sep 19 '22 01:09

Dan Jones