Hi everyone it's been a couple of days I'm trying to solve a problem without having any response, I'm not excelling at php but I am doing my best.
I want to put automatially for download, and without saving on the server a zip called Bigzip
Inside this Bigzip : -Another zip called Smallzip
But I get error when opening the downloaded zip, it is corrupted
<?php
//Big and Small Archives names
$BzipN='Bigzip.zip';
$SzipN='Smallzip.zip';
//Big and Small Archives
$Bzip = new ZipArchive();
$Szip = new ZipArchive();
//File path
$file_path=$_SERVER['DOCUMENT_ROOT'].'/PF/';
zipFilesAndDownload($BzipN,$SzipN,$Bzip,$Szip,$file_path);
function zipFilesAndDownload($BzipN,$SzipN,$Bzip,$Szip,$file_path)
{
//create the file and throw the error if unsuccessful
if ($Bzip->open($BzipN, ZIPARCHIVE::CREATE )!==TRUE) {
exit("cannot open <$BzipN>\n");
}
if ($Szip->open($SzipN, ZIPARCHIVE::CREATE )!==TRUE) {
exit("cannot open <$SzipN>\n");
}
//Add Smallzip to BigZip
$Bzip->addFile($file_path.$SzipN,$Szip);
$Szip->close();
$Bzip->close();
//then send the headers to foce download the Big zip file
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$BzipN");
header("Content-length: " . filesize($BzipN));
header("Pragma: no-cache");
header("Expires: 0");
readfile("$BzipN");
exit;
}
?>
If you have any alternatives, ideas, suggestions I will gladely take it.
Thanks