I am having this function in my class name MyMethods:
function zipDownload($file_names,$file_path){
$zip_file_name = date('Y-m-d-h-i-s').'_attachement.zip';
$zip = new ZipArchive();
if($zip->open($zip_file_name, ZIPARCHIVE::CREATE )!==TRUE) {
echo("cannot open <".$zip_file_name.">
");
}
else{
$filePathAry = explode("/",$file_path);
$count = count($filePathAry);
$path = '';
for($i=0; $i<=$count - 2; $i++){
$path .= $filePathAry[$i].'/';
}
$path = $this->baseDir().$path;
foreach($file_names as $files){
$zip->addFile($path,$files);
}
$zip->close();
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=".$zip_file_name);
header("Pragma: no-cache");
header("Expires: 0");
readfile($zip_file_name);
exit;
}
}
I am calling this by the following code from presentation layer:
//filled array with names of files:
loop over files name{
$filesAry[] = $fileName;
}
$method->zipDownload($filesAry,$zipPath);
on debugging i get this link as an individual file path:
Path : http://localhost/sites/mySite/bdc/uploader/exhibitsFiles/06_08_2014
File Name: xyb.jpg
after clicking on the download all file as attachment, it produces .zip file but it does not open as normal .zip file?
What i am missing? please help me in this. thanks.