Welcome Guest, Not a member yet? Register   Sign In
Displaying PDF
#1

(This post was last modified: 06-20-2018, 01:20 PM by donpwinston.)

I've been getting errors in my php_error_log file. The error occur in pairs (same timestamp). But my application runs fine.

[15-Jun-2018 11:33:42 America/New_York] PHP Fatal error:  Uncaught ErrorException: Cannot modify header information - headers already sent in /opt/lampp/htdocs/system/Debug/Exceptions.php:139

Stack trace:
#0 [internal function]: CodeIgniter\Debug\Exceptions->errorHandler(2, 'Cannot modify h...', '/opt/lampp/htdo...', 139, Array)
#1 /opt/lampp/htdocs/system/Debug/Exceptions.php(139): header('HTTP/1.1 500 In...', true, 500)
#2 /opt/lampp/htdocs/system/Debug/Exceptions.php(200): CodeIgniter\Debug\Exceptions->exceptionHandler(Object(ErrorException))
#3 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()
#4 {main}
  thrown in /opt/lampp/htdocs/system/Debug/Exceptions.php on line 139

The relevant code called from a controller is:

PHP Code:
...
header('Cache-Control: private');
header('Content-type: application/pdf');
ob_clean();
flush();
readfile($file);
... 

Any ideas?
Simpler is always better
Reply
#2

Has anyone tried displaying a PDF file using CI4? If I do it with the above code I get an error in my php_error_log file. But it works, I get the PDF display. If I remove the ob_clean; flush(); statements then I get the error on the screen and no PDF.
Simpler is always better
Reply
#3

You should be able to display it in an html iframe loading the file, but the web browser should also display it.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

Use the following:
$this->response->setHeader('Cache-Control', 'private');
$this->response->setHeader('Content-type', 'application/pdf');
readfile($file);
Simpler is always better
Reply




Theme © iAndrew 2016 - Forum software by © MyBB