You can use the readStream
and writeStream
to copy a file (or all files from a folder) from one disk to another keeping the memory usage low.
// List all the files from a folder$files = Storage::disk('origin')->allFiles('/from-folder-name'); // Using normal get and put (the whole file string at once)foreach($files as $file) { Storage::disk('destination')->put( "optional-folder-name" . basename($file), Storage::disk('origin')->get($file) );} // Best: using Streams to keep memory usage low (good for large files)foreach ($files as $file) { Storage::disk('destination')->writeStream( "optional-folder-name" . basename($file), Storage::disk('origin')->readStream($file) );}
Tip given by @alanrezende