Jun 9, 2020
0
Level 11
AWS-S3 unable to download a zip file
Hi Mates, in my project I'm able to upload zip file to AWS s3 and when I'm trying to download getting a network error. any help that would be great.
$zip_file = Carbon::now()->format('m-Y').'.zip';
$zip = new \ZipArchive();
$zip->open($zip_file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
$path = storage_path().'/docs';
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
foreach ($files as $name => $file)
{
// We're skipping all subfolders
if (!$file->isDir()) {
$filePath = $file->getRealPath();
// extracting filename with substr/strlen
$relativePath = 'docs/' . substr($filePath, strlen($path) + 1);
$zip->addFile($filePath, $relativePath);
}
}
$zip->close();
Storage::disk('docs')->putFileAs('', $zip_file, $zip_file);
Storage::disk('docs-reports')->put($zip_file, $zip_file);
Please or to participate in this conversation.