I am trying to force users to download a file.
Problems:
1. Mozilla opens the download dialog correctly, but appends ".php" to the filename.
2. IE does not open a dialog at all.
Below is my code.
$file_name="myfile.ext";
if(file_exists($file_name)){
session_cache_limiter("");
header('Content-type: application/octet-stream');
header('Content-Disposition: filename='.$file_name);
}
note: I have also tried (same problems occur)
header('Content-Disposition: attachment; filename='.$file_name);
Download dialog with unknown mime types
Moderator: General Moderators
- daven
- Forum Contributor
- Posts: 332
- Joined: Tue Dec 17, 2002 1:29 pm
- Location: Gaithersburg, MD
- Contact:
Download dialog with unknown mime types
Last edited by daven on Thu Dec 19, 2002 10:20 am, edited 2 times in total.
- daven
- Forum Contributor
- Posts: 332
- Joined: Tue Dec 17, 2002 1:29 pm
- Location: Gaithersburg, MD
- Contact:
I have discovered the source of my problem, but not how to remedy it. Using headers to download a file works, but only for standard mime types. If the file has an unknown type, the problems I initially listed occur.
Ex:
This works:
for a *.pdf file
header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename=$file_name.pdf");
header("Connection: close");
This does not:
for an unknown file type (let's call it *.zzz)
header("Content-type: ?"); // no content type will work, since *.zzz is not recognized. I have tried many different ones
header("Content-Disposition: attachment; filename=$file_name.zzz");
header("Connection: close");
My problem is that I have a non-standard file type that I need users to download. Any suggestions? I am currently zipping the file and having the users download the zip, but I need to get away from that.
Ex:
This works:
for a *.pdf file
header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename=$file_name.pdf");
header("Connection: close");
This does not:
for an unknown file type (let's call it *.zzz)
header("Content-type: ?"); // no content type will work, since *.zzz is not recognized. I have tried many different ones
header("Content-Disposition: attachment; filename=$file_name.zzz");
header("Connection: close");
My problem is that I have a non-standard file type that I need users to download. Any suggestions? I am currently zipping the file and having the users download the zip, but I need to get away from that.