[thelist] ColdFusion: Forcing Download

jon steele jjsteele22 at yahoo.com
Mon Apr 15 19:25:02 CDT 2002


Hi List,

How can I force a download of a pdf file with ColdFusion, rather than Adobe displaying the file in
the browser?

Thanks
Jon


<tip type="PHP">
Use the following function to force a download in PHP, instead of having the browser display the
file:

<?
  function force_download($path)
           global $HTTP_USER_AGENT;
           $file=basename($path);
           $size = filesize($path);
           header("Content-Type: application/octet-stream");
           header("Content-Type: application/force-download");
           header("Content-Length: $size");
           // IE5.5 just downloads index.php if we don't do this
           if(preg_match("/MSIE 5.5/", $HTTP_USER_AGENT))

                   header("Content-Disposition: filename=$file");
           } else

                   header("Content-Disposition: attachment;filename=$file");
           }
           header("Content-Transfer-Encoding: binary");
           $fh = fopen($path, "r");
           fpassthru($fh);
   }
?>
</tip>

__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/



More information about the thelist mailing list