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.
1// List all the files from a folder 2$files = Storage::disk('origin')->allFiles('/from-folder-name'); 3 4// Using normal get and put (the whole file string at once) 5foreach($files as $file) { 6 Storage::disk('destination')->put( 7 "optional-folder-name" . basename($file), 8 Storage::disk('origin')->get($file) 9 );10}11 12// Best: using Streams to keep memory usage low (good for large files)13foreach ($files as $file) {14 Storage::disk('destination')->writeStream(15 "optional-folder-name" . basename($file),16 Storage::disk('origin')->readStream($file)17 );18}
Tip given by @alanrezende