[thelist] ColdFusion: Forcing Download

Matt Liotta mliotta at r337.com
Mon Apr 15 19:45:00 CDT 2002


You can use <cfheader> to set whatever headers you want just like the
PHP code does. It is specifically using the header
"application/force-download" in this case. Not sure that that particular
header works with all browsers.

-Matt

-----Original Message-----
From: thelist-admin at lists.evolt.org
[mailto:thelist-admin at lists.evolt.org] On Behalf Of jon steele
Sent: Monday, April 15, 2002 5:53 AM
To: TheList Evolt
Subject: [thelist] ColdFusion: Forcing Download

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/
--
For unsubscribe and other options, including
the Tip Harvester and archive of thelist go to:
http://lists.evolt.org Workers of the Web, evolt !




More information about the thelist mailing list