I've wrote the function to zip the files and stream out
//$filesToStream : can be array or just file string. //$dir : directory of file function zipAndStream($filesToStream,$dir){ $file = 'tempfile'.rand(9999,1000).".zip"; $zip = new ZipArchive; $res = $zip->open( $file , ZIPARCHIVE::OVERWRITE ); if ($res === TRUE && file_exists($dir.'/'.$filename) ) { if(is_array ($filesToStream)){ $filecount=0; foreach($filesToStream as $filetostream){ $zip->addFile($dir.'/'.$filetostream,$filetostream); $filecount++; $filename = substr($filetostream,0,strrpos($filetostream,'.')); } if($filecount!=1){ $filename = 'files'; } }else{ $zip->addFile($filedir.'/'.$filestostream,$filestostream); $filename = substr($filestostream,0,strrpos($filestostream,'.')); } $zip->close(); header("Content-Type: application/zip"); header("Content-Length: " . filesize($file)); header("Content-Disposition: attachment; filename=\"".$filename.".zip\""); readfile($file); } else { listfile(); } unlink($file); }to verify that your host server has zip extension try this
if(!extension_loaded('zip'))print_r('ZIP Extension Is Disable
');