Link to home
Start Free TrialLog in
Avatar of roscoeh23
roscoeh23

asked on

Problem with PHP download script.

I have a problem with my download script. It is meant to downlaod a longblob from the mysql database. The problem is it does not work safari (it tried to download the php file) or IE7 - (It is corrupt) but works on ie6 and firefox. Any ideas where I am going wrong?

<?php
if(isset($_GET['id']))
{
// if id is set then get the file with the id from database
include("/home/trisco/public_html/secure/scripts/connect.php");

$id    = $_GET['id'];
$query = "SELECT file_name, type, size, content FROM results WHERE id = '$id'";

$result = mysql_query($query) or die(mysql_error());;
list($file_name, $type, $size, $content) =                                  mysql_fetch_array($result);

/*echo $file_name;
echo $type;
echo $size;*/


header("Content-Type: $type");
header("Content-Disposition: attachment; filename=$file_name");
header("Content-Length: ".filesize($file));
header("Accept-Ranges: bytes");
header("Pragma: no-cache");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-transfer-encoding: binary");

echo $content;
exit;

}

?>
Avatar of Joe Wu
Joe Wu
Flag of Australia image

Have you tried removing some of the header lines to try and identify if they could potentially be the problem with safari and ie7?

ie maybe just have the essentials for now:

header("Content-Type: $type");
header("Content-Disposition: attachment; filename=$file_name");
echo $content;

Also may I ask why you are not just using the $size variable for this line?:
header("Content-Length: ".filesize($file));
ASKER CERTIFIED SOLUTION
Avatar of waygood
waygood

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial