Search This Blog

Google Analytics

Tuesday, July 08, 2008

Force Save As Download On a File in PHP

<?php
$strPhyFileName = "FILE PATH HERE!!!";
$strSaveAs = "FILE NAME TO SAVE AS"; 
$size = filesize($strPhyFileName);
header("Content-Type: application/download"); 
header("Content-Length: $size"); 
header("Content-Disposition: attachment; filename=".$strSaveAs); 
header("Content-Transfer-Encoding: binary"); 
$fh = fopen($strPhyFileName, "r"); 
fpassthru($fh);
?>

2 comments:

  1. I recommend Google Code Prettify for you to embed any highlighted code into your blog.

    ReplyDelete
  2. Thanks dude.

    Having the intention to use google's since months back but then never attempt to change.

    ReplyDelete

Do provide your constructive comment. I appreciate that.

Popular Posts