Jump to content

PDF retrevial and display


atomicx6637

Recommended Posts

I have a PHP page that retrieves a PDF from a location on my server that isn't in the web server home path, for security reasons. When I try to retrieve the file on my development server everything works great, but when I try it on my account with HostGator it opens the PDF and I get an error after Adobe opens. "There was an error opening this document. The file is damaged and could not be repaired"

 

Here is the code I'm using

 

                $file = $file_info->file_name;

                if(file_exists($file))
                {
                        header('Content-Description: File Transfer');
                        header('Content-Type: application/mime-type');
                        header('Content-Disposition: inline; filename='.basename($file));
                        header('Content-Transfer-Encoding: binary');
                        header('Expires: 0');
                        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                        header('Pragma: public');
                        header('Content-Length: ' . filesize($file));
                        ob_clean();
                        flush();
                        readfile($file);
                }

 

when I present it with a browser that is fails.

 

I have been racking my brain for hours. I would appreciate some help.

 

Thanks

Troy

Link to comment
https://forums.phpfreaks.com/topic/247913-pdf-retrevial-and-display/
Share on other sites

I am going to assume that HostGator are using an old version of PHP that i am,

I am also assuming that you have

ob_start();

in your script (above what you have posted)

 

with that said,

try changing the line

ob_clean();

to

if (ob_get_length() > 0) @ob_end_clean();

 

in truth you could use the if or the @ and the above is kinda overkill..

 

Hope this helps

 

-MadTechie

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.