note 36325 deleted from function.readfile by aidan
| From: | aidan@php.net | Date: | Fri, 24 Sep 2004 01:28:43 +0000 |
| Subject: | note 36325 deleted from function.readfile by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77281@lists.php.net to get a copy of this message | ||
Note Submitter: Patrick Premartin (pprem at pprem.net)
----
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.