Archive

Posts Tagged ‘php’

Forced Download – PHP

February 14th, 2011 prakash No comments

Use this code :

  1. $file = 'index.php';
  2. if (file_exists($file)) {
  3.  header('Content-Description: File Transfer');
  4.  header('Content-Type: application/octet-stream');
  5.  header('Content-Disposition: attachment; filename='.basename($file));
  6.  header('Content-Transfer-Encoding: binary');
  7.  header('Expires: 0');
  8.  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  9.  header('Pragma: public');
  10.  header('Content-Length: ' . filesize($file));
  11.  ob_clean();
  12.  flush();
  13.  readfile($file);
  14.  exit;
  15. }
Categories: Uncategorized Tags: ,