[thelist] Problem with PDF Download via PHP

Damien COLA damiencola at wanadoo.fr
Wed Dec 24 13:00:19 CST 2003

might be related to cache problem with IE :

Have a look at this message taken from http://in2.php.net/header , they
suggest to you : don't use READFILE() and use cache control to force IE
into saving the file into temp folder. Be careful not to use
SESSION_START() or the headers would already be sent :

15-Oct-2003 12:27 
Some browsers out there on the Internet act funny, especially with
Internet Explorer (IE), so this script will help.  This is ony an
example for displaying the PDF.  You can REM out the code and change
it to make it be a downloadable file instead.



    header("Pragma: public");
    header("Expires: 0"); // set expiration time
    header("Cache-Control: must-revalidate, post-check=0,

    header("Content-Type: application/pdf");
    header("Content-Length: ".$filesize);
    header("Content-Disposition: inline; filename=$filename");
    header("Content-Transfer-Encoding: binary");
    //Can't use readfile() due to poor controlling of the file
    //(IE have this problems)...

    //use fopen() instead of readfile...
    $fp = fopen($filepath, 'rb');
    $pdf_buffer = fread($fp, $filesize);
    fclose ($fp);


    print $pdf_buffer;
    //Required, to keep IE from running into problems
    //when opening the file while downloading or downloading...
    //(IE been acting strange lately...)

-----Original Message-----
Subject: [thelist] Problem with PDF Download via PHP

More information about the thelist mailing list