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...

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 ?


regards,
Matt.

-- 
_______________________________________________
Matt Pegg
IT Specialist
Abacus Business Machines
Ballarat, Australia.
_______________________________________________

Reply via email to