note 31064 deleted from function.header by sniper
| From: | sniper@php.net | Date: | Sun, 07 Sep 2003 21:41:12 +0000 |
| Subject: | note 31064 deleted from function.header by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-55642@lists.php.net to get a copy of this message | ||
Note Submitter: joakim@locotech.fi
----
There's been a lot of talk about the .php -extension being added to the file while forcing
downloads to a Mozilla Client.
I had the same problem and followed all the documented suggestions found here. Still, nothing seemed
to work. I added the slash before the "?" in the url: send.php/?send=7 and so forth.
Then I discovered the last file worked, but not the three first ones in my list of downloadables.
This is because there are scandinavian chars "ä" and "ö" (a and o -umlauts) in
the first three filenames. So naturally I wrote a quick fix to replace those chars if
"Gecko" is found in the user_agent variable and now it works:
$user_agent=${"HTTP_USER_AGENT"};
if (strpos($user_agent,"Gecko")) $filename=str_replace
("ö","o",str_replace("ä","a",strtolower($filename)));
$file="files/$send";
header("Content-type: octet/stream\n");
header("Content-transfer-encoding: binary\n");
$head="Content-Disposition: attachment; filename=".$filename."\n";
header($head);
header("Content-Length: ".filesize($file));
readfile($file);
exit;
I am also changing the filename to lowercase so that I don't have to check for large Ä:s and
Ö:s. Yes, I am lazy. :)
Hope this helps.
-Joakim