0

I'm having trouble with displaying PDF file in a div or iFrame. PDF files contain private information so i cant give direct access to this files. I'm reading file with PHP and then `feeding' it to the browser. I'm using these headers:

    header('Content-Type: application/pdf');
    header('Content-Disposition: attachment; filename="myPdf.PDF"');
    header("Content-Transfer-Encoding: binary");
    header('Accept-Ranges: bytes');
    header("Cache-control: private");
    header('Pragma: private');
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

And this is the output code:

    @ob_end_clean();
    if ($file_h = fopen($file, 'r'))
    {

        while (!feof($file_h))
        {
            $buffer = fread($file_h, filesize($file));
            print($buffer); 
            flush();
        }
        fclose($file_h);
    }

Apparently this is ideal for downloading files but now i need to load them in a DIV or iFrame. And it just doesn't work. iFrame does a download dialog, <object> doesn't work at all and <embed> show's screwy plugin problems.

Any suggestions?

rinchik
  • 2,642
  • 8
  • 29
  • 46
  • 1
    look here [http://stackoverflow.com/questions/4679756/show-a-pdf-files-in-users-browser-via-php-perl][1] [1]: http://stackoverflow.com/questions/4679756/show-a-pdf-files-in-users-browser-via-php-perl – mkjasinski Mar 16 '13 at 00:32
  • Thanks! That helped! I just needed to change `Content-Disposition: attachment` to `Content-Disposition: inline` – rinchik Mar 16 '13 at 01:00

0 Answers0