Problem with PHP download script.

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

    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));
    LVL 9

    Accepted Solution

    header('Content-Type: application/octet-stream'); // instead of whatever the filetype is

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    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 a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    732 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now