Page 1 of 1

Download dialog with unknown mime types

Posted: Tue Dec 17, 2002 1:29 pm
by daven
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);

Posted: Wed Dec 18, 2002 6:44 am
by evilcoder
my question is why?

are you spreading malicous programs? thats the only reason someone would want a forced download!

Posted: Wed Dec 18, 2002 8:33 am
by daven
Sorry. I named the topic badly. "Forced download" in the sense that I want to have the download dialog popup. I need to have users download a software patch.

Posted: Wed Dec 18, 2002 12:38 pm
by Takuma
I need to use that too, I need it to make user download a SQL file on my forum.

Posted: Thu Dec 19, 2002 10:26 am
by daven
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.