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()