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
Enjoyed This Tip?
Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.
Recent Courses
PhpStorm Junie AI for Laravel Projects: Crash Course
7 lessons
36 min
NativePHP: Build Mobile App with Laravel
11 lessons
2 h 2 min read
Laravel HTTP Client and 3rd-Party APIs
7 lessons
50 min