note 36325 added to function.readfile
| From: | Patrick at rn2 dot php dot net | Date: | Sun, 05 Oct 2003 16:16:54 +0000 |
| Subject: | note 36325 added to function.readfile | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-57838@lists.php.net to get a copy of this message | ||
Hi
To force a download on MSIE for Windows, you don't have to use "attachment", but you
need it for all other browsers. The correct code for that is then:
<?php
$filename=""; // the name the file will have on client computer
$file_to_download=""; // the name the file has on the server (or an FTP or HTTP request)
$user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
header( "Content-type: application/force-download" );
if ((is_integer (strpos($user_agent, "msie"))) && (is_integer (strpos($user_agent,
"win")))) {
header( "Content-Disposition: filename=".$filename);
} else {
header( "Content-Disposition: attachment; filename="$filename);
}
header( "Content-Description: File Transfert");
@readfile($file_to_download);
?>
This code work properly on Windows (MSIE, Netscape, Mosilla, Opera) and Mac (MSIE, Netscape).
For the Mac, there is a little problem: if the file is recognized by the OS, it will open it and not
force save to disk. To prevent this, ask your clients to use "save link to disk" and not
click on it.
----
Manual Page -- http://www.php.net/manual/en/function.readfile.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+36325
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+36325&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+36325&report=yes
Search Tool -- http://master.php.net/manage/user-notes.php