Forum Moderators: open
I have a question that I hope someone can help me with. I've done some research on Content-Disposition and Content-Type in a HTML file's header to force downloading files like PDF's instead of automatically displaying them in the browser but I'm a but confused as to how I should have them placed in my HTML file.
I've currently got the following, which doesn't work:
<META HTTP-EQUIV="Content-Type" CONTENT="application/octet-stream">
<META HTTP-EQUIV="Content-Disposition" CONTENT="attachment; filename=somefile.pdf">
Wouldn't that set the content-type of the page instead of just the file? The RFC2183 documentation says to use the two attributes I posted, but doesn't specify how they should look within a HTML page.
So I guess what I'm asking is whether it is possible to override a server's MIME settings and force the download of a file of a certain extension without having to use something like PHP?
thanks a lot.
Those are not MIME headers, but merely meta information. The headers must be sent by the server, before the actual page is sent to the browser. Once the meta tag is read by the browser, it is already too late.
You have two options:
1) make changes to your Web server to modify the headers for the particular page
2) use a server side scripting language (such as PHP/Perl/ASP) which can then set the headers you need
but if I were to use something like this
<?
$files="info.zip";
$filenames="info.zip";
$url= "/www/download/";
$total=$url . $files;
Header ( "Content-Type: application/octet-stream");
Header ( "Content-Length: ".filesize($total));
Header( "Content-Disposition: attachment; filename=$filenames");
readfile($total);
?>
1. would I include it at the top of my html page?
2. does the content-type apply to all downloads on that page and does it apply the "attachment" part to them, thus forcing a save dialog screen to show up?
thanks
[edited by: tedster at 2:05 am (utc) on May 10, 2004]
[edit reason] fix side-scroll [/edit]
You might even consider using winzip or similar to make a self-extracting .exe out of it - then all the end-user has to do is double-click on it....