Occasionally when https://testmyspeed.onl/ https://solitaire.onl/ I download content online, some files require me to use winrar to unzip them. What exactly are zipped files and how does unzipping them work? Also whats the purpose behind zipping files?
May 7, 2020
7
Level 2
Zip files and download the zip.
Hello
Actually I was trying to zip the files uploaded. I have the array of the path of files fetched from DB. I tried to implement from the articles but it gives an error while sending the response. It says zip file not found. I manually tried to create the zip file, but it after controller calls, the manually created file deletes automatically. Please give your suggestions on this. i tried this
public function show(Project $project, $type)
{
try {
$files = $project[$this->types[$type]]->pluck('file')->map(static function (File $file) {
return $file->getOriginal('url');
});
if ($files->isEmpty()) {
throw new \Exception();
}
$zip_file = $this->types[$type] . '.zip';
$zip = new ZipArchive;
if ($zip->open(public_path($zip_file), ZipArchive::CREATE | ZipArchive::OVERWRITE) === TRUE) {
foreach ($files as $value) {
$zip->addFile($value, public_path($value));
}
$zip->close();
}
return response()->download(public_path($zip_file));
} catch (\Exception $e) {
throw new NotFoundHttpException();
}
}
Please or to participate in this conversation.