www.webdeveloper.com
Results 1 to 2 of 2

Thread: download problems

  1. #1
    Join Date
    Jun 2009
    Location
    Washington (State)
    Posts
    58

    download problems

    Every search I do, I get slightly different descriptions of what headers are needed to do a file download. What I want is the ability for a person to backup an SQL database, and have it downloaded as a zipped file. I also want the Save As... dialog box to open up.

    The following code works differently in different browsers.
    PHP Code:
    $filename "Participant-Backup".Date("Y-m-d").".sql.bz2";
    $backup_string "/usr/local/mysql/bin/mysqldump --user=Administrator --password=$_SESSION[userPass] --opt CnR | bzip2";

    header("Content-Type: application/force-download");
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/download");


    header("Expires: 0");
    header("Cache-Control: no-cache");
    header("Pragma: no-cache");


    header("Content-Type: application/zip");
    header("Content-Transfer-Encoding: binary");
    header("Content-Disposition:*attachment;*filename=$filename");

    passthru($backup_string); 
    It was downloading correctly in Safari, but no dialog box. I rearranged some headers, and now it won't work at all in Safari. All I get a blank file with the right filename.

    Firefox gets and saves the file, but names it backup.php, which is the name of the script. No dialog box.

    Chrome works just fine.

    IE. ugh. It fails, with a "cannot connect to server" error message.

    Every search I do I get different ideas, and I have not been able to find much about what these headers are "supposed" to do. Any help to get this up and working would be appreciated.

    --Dave

  2. #2
    Join Date
    Sep 2006
    Location
    Bucharest, RO
    Posts
    940
    AFAIK, it is not right to send multiple headers with the same name (at least not for Content-Type). That is why you are getting different results. Try this:
    PHP Code:
    $filename "Participant-Backup".Date("Y-m-d").".sql.bz2";
    $backup_string "/usr/local/mysql/bin/mysqldump --user=Administrator --password=$_SESSION[userPass] --opt CnR | bzip2";

    header("Content-Type: application/octet-stream");
    header("Expires: 0");
    header("Cache-Control: no-cache");
    header("Pragma: no-cache");
    header("Content-Disposition: attachment; filename=\"$filename\""); // notice that I removed the asterisks (*) and added quotes around $filename

    passthru($backup_string); 
    Try that, let us know if it works.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles