hy all, I want to make code for download multiple file in php so I make in zip file. my code work and can create sip file but when I want to open the zip file appear error message like this " the archive is either is unknown format or damaged ". I already attach the error message
this is my full code
function zipFilesAndDownload($file_names,$archive_file_name,$file_path)
{
$zip = new ZipArchive();
//create the file and throw the error if unsuccessful
if ($zip->open($archive_file_name, ZipArchive::CREATE )!==TRUE) {
exit("cannot open <$archive_file_name>\n");
}
else {
$zip->open($archive_file_name, ZipArchive::CREATE );
//add each files of $file_name array to archive
foreach($file_names as $files)
{
$zip->addFile($file_path.$files,$files);
//echo $file_path.$files,$files."<br />";
}
$zip->close();
//then send the headers to foce download the zip file
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$archive_file_name");
header("Pragma: no-cache");
header("Expires: 0");
readfile("$archive_file_name");
exit;
}
}
then here I call the function
$file_names = array('makeZipinPHP.jpg','Speed_Kills.wav','tick.jpg','webinfopedia.com.txt');
$archive_file_name=$name."$ico.zip";
$file_path=$_SERVER['DOCUMENT_ROOT'].'/download/';
zipFilesAndDownload($file_names,$archive_file_name,$file_path);
can some one give example about this problem? I get stack with my project because of this
thank you in advance