Re: PHP/Mysql: Making binary field available for download - extra browser window ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Matthew Pegg wrote:
Hi all,

Working on a PHP script at the moment where I want to be able to
extract a file (PDF file) from a mysql database and force the popup
of the File Download dialog, to allow the user to either save or open
the document (ie. and bypass loading the file using the browser's plugin)
I've found solutions on the net for doing this with a file using readfile()
but if I can get away with it, I don't want to create temporary files...

not having temporary files and even the code you use have nothing to do with
the extra window problem - that is a client side issue over which php has no
control .. it's down to the browser settings (possibly) or (more likely) the
target attribute of the link in question.


Here's what I've got so far (truncated...):
    <?
    ..
    // db query string extract the PDF file
    $result = mysql_query("select file_data from brochure where id=1",$connection);

    $row    = mysql_fetch_array($result);
    $lengths = mysql_fetch_lengths($result);

    // Grab the file contents as returned from the db
    $pdf_brochure = $row["file_data"];

    // setup headers to force download of $pdf_brochure into crap.pdf
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private",false); // required for certain browsers
    header("Content-Type: application/force-download");

    header("Content-Disposition: attachment; filename=\"crap.pdf\";" );
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: " . $lengths[0]);

    // send the file to stdout
print $pdf_brochure; // <---- problem might be here.... exit();

    ?>

This almost works but the problem is that this code still spawns a new empty
browser window, and I don't know how to prevent this.... Can anyone help ?

don't open a new window to download it then ... i.e. don't use 'target="_blank"' in
the html defintion of the relevant link.



regards,
Matt.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux