[ciapug] fpassthru file download
John Rearick
jrearick at bobbis.net
Wed Dec 5 16:49:35 CST 2007
The following code seems to work in IE 6. There are also a lot of
comments at the readfile page http://us2.php.net/manual/en/
function.readfile.php
header("Content-type: application/force-download");
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($file));
header("Content-disposition: attachment; filename=\"".$name."\"");
readfile($file);
John
On Dec 5, 2007, at 3:33 PM, Barry Von Ahsen wrote:
> so I had to revisit this, and it seems a lot of people have this
> problem, but haven't found a solution.
>
> I want users to download a file that preferably lives outside of
> the webroot. it works fine in FF and IE7, but IE6 won't pick up
> the file name I specify, it wants to name it my page name
> (download.php) - I accept that IE6 SP2 will force a download, I
> just want the name to be right. anybody fixed this?
>
>
> here's my code:
>
> $ext = pathinfo($thefile,PATHINFO_EXTENSION);
> $file = $download_dir.$thefile;
> if($fh = fopen($file,"rb")) {
> /*if(function_exists(mime_content_type)) {
> header("Content-Type: ".mime_content_type($file));
> } else {*/
> switch($ext) {
> case "pdf": header("Content-Type: application/pdf"); break;
> case "doc": header("Content-Type: application/msword"); break;
> case "csv": header("Content-Type: application/msexcel"); break;
> case "exe": header("Content-Type: application/force-download");
> break;
> case "mp3": header("Content-Type: audio/mpeg"); break;
> case "txt": header("Content-Type: text/plain"); break;
> case "zip": header("Content-Type: application/zip"); break;
> default: header("Content-Type: application/force-download"); break;
> }
> //}
> header("Content-Disposition: attachment; filename=\"$thefile\"");
> header("Content-Length: " . filesize($file));
> header('Cache-Control: public');
> header('Pragma: public');
> fpassthru($fh);
> exit();
> }
> _______________________________________________
> ciapug mailing list
> ciapug at cialug.org
> http://cialug.org/mailman/listinfo/ciapug
More information about the ciapug
mailing list