6

I have files in my local storage public/images/users and I want to move these files to cloud storage AWS S3 using the Laravel filesystem.

Route::get('upload-local-files-to-s3', function() {
        $documentFiles = Storage::disk('public')->files('images\\users\\');
        foreach ($documentFiles as $documentFile){
        $filesystem  = new Filesystem();
        $contents = $filesystem->get($documentFile);
        Storage::disk('s3')->put('documents\\'. $documentFile, $contents)
        echo $documentFile . ' Uploaded. '. '<br>';
    }
});

This code uploads the files to S3 but it creates new folders inside the documents/images/users while I want to upload files inside the documents folder.
And how can I create File Object from above $documentFile variable name?
Because I want to use these following functions from the file object.

getClientOriginalExtension()
getClientMimeType()
getFilename()
getClientOriginalName()
Salim Djerbouh
  • 10,719
  • 6
  • 29
  • 61
Waqas Mehmood
  • 199
  • 3
  • 17

0 Answers0