I’m asking for your help because I can’t figure out where the error is.
I’m creating a backup zip file of a folder in Laravel and I want to automatically save it on the Amazon S3 server. I’ve already set up the entire FyleSystem, ID keys etc.. the point is that now on the Amazon server it only saves the name of the file and not the archive .zip, can I ask for your help to understand why it doesn’t save the entire archive but only the name?
This is code
$zip = new ZipArchive;
$azienda = User::value('azienda');
$fileName = time() . $azienda . ".zip";
if ($zip->open(public_path($fileName), ZipArchive::CREATE) === TRUE) {
$files = File::files(public_path('/images/images'));
foreach ($files as $key => $value) {
$relativeNameInZipFile = basename($value);
$zip->addFile($value, $relativeNameInZipFile);
}
$zip->close();
};
Storage::disk('s3')->put('public/backup', $fileName);
thanks a lot to everyone
2
Answers
Storage::put
takes either a string contents or a file resource. It does not take file names, and will treat it as the string it is.https://laravel.com/docs/10.x/filesystem#storing-files
or, for lower memory usage, stream it:
You are storing file name instead of content!
Try this: