How to retrieve pdf from mysql and display using php [duplicate]

I have an retrieving pdf from mysql. I have successfully retrieved the content of pdf from mysql but not able to display it on the website. Its giving me warning on header function I'm using to display it. Here is the code.


    //to get unique name
    $fileName = time().".pdf";
    //to display as pdf
    header( "Content-type: application/pdf" );
    header( "Content-disposition: attachment; filename=".$fileName );
    echo $pdf;

but I'm constantly getting this error.

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp64\www\SRFRS\Project-page.php:176) in C:\wamp64\www\SRFRS\Project-page.php on line 212

I have looked for many solutions online but nothing worked for me. If you could give me a solution or any other way to display pdf on my website.

Read more here:

Content Attribution

This content was originally published by Samist at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: