I'm having issues force downloading a zip file which is stored on the server. I have the full script below, this script contains functions only, the function is called from a separate file where header information is sent .
function goZipper($files, $destination = '', $originPath = '', $overwrite = true) {
if(file_exists($destination) && !$overwrite) {
echo"File exists";
return false;
}
if(count($files)){
//create a zip archive
$zip = new ZipArchive();
$destination = $destination .'/'.'archive - '.date('m-d-Y_h:i-a').'.zip';
if($zip->open($destination, $overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true){
echo"Error opening destination";
return false;
}
foreach($files as $file){
$base = $originPath . $file;
$zip->addFile($base, $file);
}
$zip->close();
return($destination);
}
else{
return false;
}
}
function downloadZipper($fullFilePath){
$fileName = basename($fullFilePath);
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=$fileName");
header("Content-Length: " . filesize($fullFilePath));
readfile($fileName);
exit;
}
A full server path (including the file) is passed in to the function. I'm then extracting the basename for input in to the headers. I can't see any issues with this. I get the error 'Cannot modify header information - headers already sent'