Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Problem with PHP download script.

Posted on 2007-10-05
Medium Priority
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;


Question by:roscoeh23
LVL 21

Expert Comment

ID: 20026708
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));

Accepted Solution

waygood earned 2000 total points
ID: 20034023
header('Content-Type: application/octet-stream'); // instead of whatever the filetype is

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question