[thelist] Forcing IE to download a file rather than displaying it?
Kris Hedstrom
webdev at komputerart.com
Sat Dec 29 16:11:43 CST 2001
I wrote this php function awhile back to force downloads. I don't know if
you're using php or not, but it might be helpful.
function 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);
}
----- Original Message -----
From: Bob Haroche <bharoche at usa.net>
To: <thelist at lists.evolt.org>
Sent: Friday, December 28, 2001 11:44 PM
Subject: [thelist] Forcing IE to download a file rather than displaying it?
> I need to create a web space where my client can upload Word (.doc) files
> and Acrobat (.pdf) files. When the user clicks on a file link, it should
> force the browser to respond with a "save file" dialog box.
>
> Obviously, this is simple if the files are first zipped/stuffed, but
reasons
> not relevant here that's not an option.
>
> The domain is virtually hosted on unix/Apache 1.3.6. I've played around
with
> .htaccess to over-ride the mime type for these files such as:
>
> AddType application/octet-stream .doc
>
> While this works for Netscape, Internet Explorer 6 PC (and I assume
earlier
> versions as well) insist on still opening the Word documents inside the
> browser.
>
> Is there any way, other than zipping/stuffing to over-ride this behavior
and
> force a "save as..." prompt?
>
> Thanks in advance.
>
> Regards,
> Bob Haroche
> O n P o i n t S o l u t i o n s
> http://www.OnPointSolutions.com
>
>
>
>
>
>
>
>
>
> ____________________________
> O n P o i n t S o l u t i o n s
> P.O. Box 694
> Occidental, Ca 95465
> Tel: 707.874.2710
> Fax: 707.874.2716
> http://www.OnPointSolutions.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