Identifying a binary file's MIME type
Posted: Tue Jan 24, 2006 4:31 pm
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:
Here's the HTML 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.
My PHP script:
Code: Select all
<?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" );
}
}
?>Code: Select all
<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>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.