atomicx6637 Posted September 26, 2011 Share Posted September 26, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/247913-pdf-retrevial-and-display/ Share on other sites More sharing options...
MadTechie Posted September 26, 2011 Share Posted September 26, 2011 Would it be possible to attach one of the PDF's, or email me one Quote Link to comment https://forums.phpfreaks.com/topic/247913-pdf-retrevial-and-display/#findComment-1273000 Share on other sites More sharing options...
atomicx6637 Posted September 26, 2011 Author Share Posted September 26, 2011 Email is on its way. Quote Link to comment https://forums.phpfreaks.com/topic/247913-pdf-retrevial-and-display/#findComment-1273019 Share on other sites More sharing options...
MadTechie Posted September 27, 2011 Share Posted September 27, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/247913-pdf-retrevial-and-display/#findComment-1273132 Share on other sites More sharing options...
atomicx6637 Posted October 1, 2011 Author Share Posted October 1, 2011 That was it. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/247913-pdf-retrevial-and-display/#findComment-1274759 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.