PHP Download File Forcefully

In php there are some situation where you want to download file Forcefully.For that you have to use php header function. In header function you have to use Content-Type as application/octet-stream and Content-Disposition.

  header("Pragma: public");     
  header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  header("Cache-Control: maxage=1"); 
  header ("Content-Type: application/octet-stream");
  header ("Content-Length: " . filesize($absoluteFilePath));
  header ("Content-Disposition: attachment; filename=$filename");

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.