Forum Moderators: coopster

Message Too Old, No Replies

Identifying a binary file's MIME type

         

sblades

10:52 pm on Jan 24, 2006 (gmt 0)

10+ Year Member



I'm trying to set up a script that will allow site visitors to download a Windows-based application installer, which is a binary file. The problem I'm having is that Internet Explorer (Win-6.0 SP2) does not execute my PHP to create the typical download panel.

My PHP script:

<?php
if (isset($_POST['submit'])) {
$Clicked = ($_REQUEST['clicked']);
$filename = "MyProgramInstaller.exe";
$filetype = "octet-stream";
$Recip = "hello@world.net";
$Subj = "MyProgramInstaller download occurred";
$Msg = "A visitor has downloaded a copy of MyProgramInstaller.exe.";
$Sender = "downloads@website.com";
$Nickname = "Downloads";
if ((isset($Clicked)) && (file_exists($filename))) {
// Send the file.
header ("Content-Type: application/$filetype");
header ("Content-disposition: attachment; filename=$filename");
readfile ($filename);
// Send the email.
mail("$Recip", "$Subj", "$Msg", "From: $Nickname <$Sender>\r\nReply-To: $Nickname <$Sender>\r\n" );
}
}
?>

Here's the HTML form:

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<input type="hidden" name="clicked" value="TRUE">
<input src="images/nav/download.gif" type="image" name="submit" value="Download Now!" alt="Download MyProgramInstaller" class="swapformbtn">
</form>

Regarding the MIME type (var $filetype), I've tried "octet-stream", "x-msdownload", "x-compressed" and "x-zip-compressed". Those last 2 I tried when noting that in Windows "MyProgramInstaller.exe" appears with the typical ZIP icon (folder & vise clamp) and Properties/Attribute setting of "Archive."

None have worked yet in Internet Explorer, but all work in Firefox.

I should add that the web site is on a shared commercial hosting server. I will not be able to edit any Apache config files, but must settle on using a MIME type in my script that a default installation of Internet Explorer knows how to handle.

Any help is most appreciated.

coopster

11:04 pm on Jan 24, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yeah, it's that age-old MS IE *image submit* issue. If you were to dump the $_POST superglobal you will find there is no 'submit' index. Likely a 'submit_x' and 'submit_y' though.

Form processing problem with input type=image! [webmasterworld.com]

sblades

5:33 am on Jan 25, 2006 (gmt 0)

10+ Year Member



Thanks much, coopster.

<input type="image">
was indeed the source of the problem.

One simple change to my script...

if (isset($_POST['submit_x']))

... and it works perfectly in IE now.