odd acrobat reaction to streaming files

From: Date: Thu, 11 Mar 2004 04:01:02 +0000
Subject: odd acrobat reaction to streaming files
Groups: php.general 
Request: Send a blank email to php-general+get-180095@lists.php.net to get a copy of this message
I have been using a php file to stream pdf (and various other sorts of files)... Here's my code. <?php
           if         ($extension == ".doc"){$type = "application/msword";}
           else if ($extension == ".pdf"){$type = "application/pdf";}
           else if ($extension == ".exe"){$type = "application/octet-stream";}
           else if ($extension == ".ppt"){$type = "application/vnd.ms-powerpoint";}
           else if ($extension == ".xls"){$type = "application/vnd.ms-excel";}
           else if ($extension == ".xml"){$type = "text/xml";}
           else if ($extension == ".zip"){$type = "application/zip";}
           else if ($extension == ".txt"){$type = "text/plain";}
           else {
               $type="application/octet-stream";
           }
           header("Content-type: " . $type);
           header("Accept-Ranges: bytes");
           header("Content-Length: ".filesize($file));
           readfile($file);           ?>
And so this worked perfectly well when I did something like this: loadfile.php?file=name.pdf (where name.pdf is the file I am loading and loadfile.php is the name of the script). But loadfile.php?file=directory/name.pdf (when launching Adobe acrobat) would give me the error 'File Does not begin with '%PDF' ". I was able to add this header line: header("Content-Disposition: attachment;
filename=".basename($file).";");           
which forced the user to be prompted if he wanted acrobat to be loaded or to save the file.  Both options worked flawlessly. 
So why did it not work before I added this header line?  Is it a flaw in Adobe Acrobat?
Best Regards, Scott Taylor

« previous php.general (#180095) next »