Hi all,
PHP 4.2.2 on RedHat9
I have some files on my website for people to download, and I want to
generate the file location "on the fly", so the URL is held in a database.
I have a simple PHP script, pasted below. IE users are fine, but Mozilla
users actually see the file contents on screen, as garbage, instead of
being presented with the "save as" dialog.
The files for download have the .msi extension (binaries).
Can anyone see what I'm doing wrong? Do I need to send different/additional
headers?
Many thanks!
Jim
===========================================
<?php
// Retrieve the parameters
$FileID = isset($_REQUEST["ID"]) ? $_REQUEST["ID"] : -1;
// Connect to the database
$link = mysql_connect("localhost", root", "xxxxxx") or die("Could not
connect : " . mysql_error());
mysql_select_db("Downloads") or die("Could not select Downloads database");
// Is this a valid download?
$query = "SELECT * FROM DownloadItems WHERE FileID='$FileID'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$num_rows = mysql_num_rows($result);
if ($num_rows != 1)
die("Invalid Download");
// Obtain the row
$row = mysql_fetch_array($result, MYSQL_ASSOC);
// Obtain the URL
$FileURL = $row["FileURL"];
// Release the database connection
mysql_free_result($result);
// Redirect
header("Content-Type: application/force-download");
header("Location: $FileURL");
?>
Jim Willsher
Homepages at http://www.jimwillsher.co.uk