Hi,

I'm having some problems with forcing a file download.
I want to use the script to force the download of .doc,.pdf and .txt files
so they don't get opened in the current browser window.
I already have a script that works on most browsers (ie5.01, netsc4.07,
netsc6.01, opera4.01 all on PC) except for IE 5.5 and Opera 5 on PC.
Macintosh browsers (both IE and Netscape) don't like my script either...
IE 5.5 just opens the file in the browserwindow, Opera 5 just opens raw code
in the browserwindow (as if they were textfiles). I already had to use a
little hack to please IE 5.5, otherwise download.php got downloaded instead
of the actual file...
Please have a look at the code below.
I know I could use a javascript popup window, but I realy would like to get
this script going...

All tips are greatly appreciated!
Thanx alot!

Bert

This is what I've got for now:

******************
<?
//download.php, a result of some serious cutting and pasting...
//download.php?file.ext will get 'file.ext' from the download directory
//download.php?somesubdir/file.ext will get 'file.ext' from 'somesubdir' in
the download directory
$what_to_get = getenv("QUERY_STRING");
//this puts cookie to know they have downloaded before
SetCookie("Download",yep, time()+36000000, "/", "www.domain.com", 0);
$size = filesize("/path/to/the/download/dir/$what_to_get");
//we wanna know the name of the file, without the directories
$my_name_is = basename($what_to_get);
//headerstuff
//use one of these 2, I don't know if it makes a difference...
//header("Content-Type: application/octet-stream");
header("Content-Type: application/force-download");
//need the size of our file
header("Content-Length: $size");
// IE5.5 just downloads download.php if we don't do this...
// for now I only check on 5.5 but what if 6.0 has the same problem??
if(preg_match("/MSIE 5.5/", $HTTP_USER_AGENT))

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

header("Content-Disposition: attachment; filename=$my_name_is");
}
header("Content-Transfer-Encoding: binary");
$fh = fopen("/path/to/the/download/dir/$what_to_get", "r");
fpassthru($fh);
exit;
?>
******************




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to