We help IT Professionals succeed at work.

Problem with PHP download script.

roscoeh23 asked
Last Modified: 2013-12-13
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?

// if id is set then get the file with the id from database

$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;


Watch Question

Joe WuDeveloper | Solutions Architect | CTO

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));
Unlock this solution and get a sample of our free trial.
(No credit card required)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.