I am trying to download a zip file using php. Download work fine but when in extract zip it say invalid file. Please help me and check my below code:
apache_setenv('no-gzip', 1);
ini_set('zlib.output_compression', 0);
$filename = "sliced Images.zip";
$upload_dir = wp_upload_dir();
$filepath = $upload_dir['basedir'];
//echo $filepath.'/'.$filename;
//echo filesize($filepath.'/'.$filename);
//die;
// http headers for zip downloads
ob_start();
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: Binary");
header("Content-Disposition: attachment; filename=\"".$filename."\"");
header("Content-Length: ".filesize($filepath.'/'.$filename));
ob_end_flush();
@readfile($filepath.'/'.$filename);