Skip to main content
Quick Tip

Copy file or all files from a folder

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

Laravel Coding with AI Agents: Cursor, Claude Code, Codex

5 lessons
1 h 01 min

Laravel Modules and DDD

16 lessons
1 h 59 min

Laravel 12 For Beginners: Your First Project

15 lessons
1 h 32 min

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.