HTTP Headers for ZIP File Downloads

maxresdefault

This tutorial will help you with generating zip files and directly download to your system. so just follow the step and you can get the zip file downloadable using the PHP code. this zip generates code will use of all system like mac, ubuntu, window and etc with a different browser.

Step 1)

copy below code in your PHP file.

<?php 

$filename = "Inferno.zip";
$filepath = "/var/www/domain/httpdocs/download/path/";

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/octet-stream");
header("Content-Disposition: attachment; filename=\"".$filename."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filepath.$filename));
ob_end_flush();
@readfile($filepath.$filename);
ob_clean();
flush();
readfile($file);
ob_clean();
flush();
exit; 
?>

Step 2)

now run the url in your browser where you can direct download the zip file.

Leave a Reply

Your email address will not be published. Required fields are marked *

23  +    =  25