note 62323 deleted from function.header by tularis
| From: | tularis@php.net | Date: | Sun, 26 Feb 2006 13:51:52 +0000 |
| Subject: | note 62323 deleted from function.header by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-104460@lists.php.net to get a copy of this message | ||
Note Submitter: luemae2 at hotmail dot com
----
I use this in a popup-window, which works just fine! The filename is sent by the
"download" link in an other php-file. More filetypes can be added.
My only Problem: The popup window remains empty whatever i do, even with ob_start and end_flush. I
want to put "download should be starting automatically, otherwise...." into the popup
window. what can I do?
$filename = $_GET['some_file_name'];
$filename = realpath($filename);
$file_extension = strtolower(substr(strrchr($filename,"."),1));
switch ($file_extension) {
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpe": case "jpeg":
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
}
if (!file_exists($filename)) {
die("file not found. Sorry.");
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: $ctype");
header("Content-Disposition: attachment;
filename=\"".basename($filename)."\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".@filesize($filename));
set_time_limit(0);
@readfile("$filename") or die("file not found. error.");