I'm using this code to stream a PDF file:


$file = $_SERVER['DOCUMENT_ROOT'] . "/file.pdf";
simple_streamfile($file);


function simple_streamfile($file)
{

   $fp = fopen($file, 'rb');
   // send the right headers
   header("Content-Type: application/pdf");
   header("Content-Length: " . filesize($file));
   // dump the file and stop the script
   fpassthru($fp);
   fclose($fp);
   exit;

}


It appears as though some readers (such as adobe acrobat) can read this file fine yet others (such as the program gv in *NIX) cannot read it.


The reason for this is that somehow a hex 0A is added before the inital %PDF-1.2 which marks the start of the PDF file causing some readers to not recognize it as a PDF file. Is there anything in this code which could possibly (always) cause an extra byte (0A) to be added before the real start of the file? And no, the file is not corrupted (I've already tried that) - this only happens when it goes through this script, and not loaded directly as example.com/file.pdf.


Scott

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



Reply via email to