Page 1 of 1

Initiating a file download problems

Posted: Wed Apr 07, 2004 12:22 pm
by Swede78
I found some code a while back, I believe at php.net, that forces a download. I've been having problems getting Netscape to handle it correctly. For some reason it adds the extension .php to the .exe file that it is downloading. It works fine in Internet Explorer.

Here's the code:

Code: Select all

<?php
$DLFile = 'http://www.abcdefg.com/file/whatever.exe';

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=".basename($DLFile).";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($DLFile));
readfile("$DLFile");
exit(); 
?>
I'm now using the more simple method of just giving a direct link to it, which works in IE as normal. It also works in NS, but doesn't give the option to save or open, like it did using the above code.

Basically, I want it to open the dialog box with the choice to save or open, and not add .php to the filename under Netscape. Anyone else have this problem, and know how to solve it?

Posted: Wed Apr 07, 2004 1:22 pm
by Chris Corbyn
I've got exactly the same problem. If netscape doesn't understand the extension it adds .php.

By the way have you tried

Code: Select all

<?php 
$DLFile = 'http://www.abcdefg.com/file/whatever.exe'; 

header("Pragma: public"); 
header("Expires: 0"); 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("Content-Type: application/exe"); 
header("Content-Disposition: attachment; filename=".basename($DLFile).";"); 
header("Content-Transfer-Encoding: binary"); 
header("Content-Length: ".filesize($DLFile)); 
readfile("$DLFile"); 
exit(); 
?>
or

Code: Select all

<?php 
$DLFile = 'http://www.abcdefg.com/file/whatever.exe'; 

header("Pragma: public"); 
header("Expires: 0"); 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("Content-Type: application/executable"); header("Content-Disposition: attachment; filename=".basename($DLFile).";"); 
header("Content-Transfer-Encoding: binary"); 
header("Content-Length: ".filesize($DLFile)); 
readfile("$DLFile"); 
exit(); 
?>
Netscape may get more info about the file type this way.

For example: Netscape handles downloading midi files rather than streaming by using content-type as Audio/Midi and therefore knows that the extension is .mid

There must be a common MIME-type to use for executables too.

My problem is trying to get a .mmf file to download since this is not a common file type and is not contained in netscapes list of MIME types.

Posted: Wed Apr 07, 2004 3:08 pm
by Swede78
Thanks for the suggestions. Unfortunately, it still tries to add .php to the filename, when I choose "Save". Damn Netscape... I used to like it better than IE. That was a few versions ago. :)

For now, I guess people will just have to save it if they use Netscape. Not a huge problem. Just trying to give the usual options that people are used to.

Any other suggestions/solutions would be appreciated!

Posted: Fri Apr 09, 2004 1:58 pm
by Chris Corbyn
I've got your answer. Read my post at

viewtopic.php?t=20510&highlight=

I was so chuffed when I got it to work.

Good luck