Failed – Network Error when Downloading Files using PHP Headers

Sometime this error occurs when we download file using Headers. This happened because the file size is different from the one previously specified or something network connection issue during the download. Please ensure “Content-Length:” filesize value not null.

 header("Content-Type: application/octet-stream");
 header("Content-Transfer-Encoding: Binary");

 header("Content-Length: ".filesize($path));

 header("Content-Disposition: attachment; filename=\"".basename($path)."\"");

 header("Expires: 0");

 header("Cache-Control: no-cache, must-revalidate");

 header("Pragma: no-cache"); 
 readfile($path);

 exit;

Leave a Reply

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