Skip to content

Instantly share code, notes, and snippets.

Last active June 6, 2022 15:33
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Upload files from public (or any) disk to AWS S3 in Laravel without using any external tools.
use Illuminate\Support\Facades\Storage;
$public = Storage::disk('public');
$s3 = Storage::disk('s3');
$files = $public->files(null, true);
foreach ($files as $file) {
echo 'Uploading ', $file, '...', PHP_EOL;
$s3->put($file, $public->readStream($file), ['visibility' => 'public']);

To use it, first set the below variables in your .env and run php artisan config:cache.


In project folder, create a file named e.g., pu2s3.php and paste the Gist's content in it. Thenafter, run below command:

php artisan tinker

>>> require 'pu2s3.php';

Then just wait for it to finish.

Copy link

dev1983 commented Mar 17, 2021

Can you please also make a way that we can upload videos all from s3 to you tube filtered from mysql db ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment