Problem on Header

php India
  • 14 years ago
    I retrieve the image from the database. I want to display that image. For that i use header.
    But i will get eroor. like

    header("Content-type: image/jpg");


    Warning: Cannot modify header information - headers already sent by (output started at c:\program files\easyphp1-8\www\mssi\images1.php:5) in c:\program files\easyphp1-8\www\mssi\images1.php on line 148









  • 14 years ago
    If you have any output that is sent to the browser before you try and call header() then header's will already have been sent.

    Output can be any echo statement, or even just a space before the first opening <? tag.

    Have a look at http://uk2.php.net/manual/en/function.header.php for more information on the header() function.

    You can check if the headers have already been sent with
    <? 
    if(!headers_sent()){
    //headers have not been sent, send headers
    header("Content-type: image/jpg");
    }
    else{
    //headers have been sent
    }
    ?>









     
    Have a look at output buffering to find out more about some techniques to help stop any content being sent until you are ready to.









Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“In order to understand recursion, one must first understand recursion.”