HTTP Headers for ZIP File Downloads

HTTP Headers for ZIP File Downloads

HTTP Headers for ZIP File Downloads

This tutorial will help you with generating zip files and directly downloading them to your system. So just follow the step, and you can get the zip file downloadable using the PHP code. This zip generates code that will be used on all systems, like Mac, Ubuntu, Windows, etc., with a different browser.

Step 1)

Copy the code below into 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 directly download the zip file.

0 Comment

Leave a Reply

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