note 107069 modified in book.image by danbrown
| From: | danbrown@php.net | Date: | Fri, 06 Jan 2012 19:18:44 +0000 |
| Subject: | note 107069 modified in book.image by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-185416@lists.php.net to get a copy of this message | ||
In case your script is using output-buffering-functions somewhere, then you have to clear the buffer
first ( with ob_clear() ), before outputting an image with a function like imagepng().
And you should make sure that no buffer will get send after outputing an image by using the
ob_end_flush()-function.
Furthermore you should check if a buffer has already been flushed somewhere before. This can be done
using the headers_sent()-function.
Here is the full solution:
<?php
if(headers_sent()){
die('Headers have been send somewhere within my script');
}
ob_clean(); //Clears the buffer
header('Content-type: image/png');
imagepng($img, NULL, 0, NULL);
ob_end_flush(); //Now we send the header and image plus we make sure that nothing will get send from
now on (including possible shutdown-functions and __destruct()-methods) till the end of
page-execution
?>
--was--
In case your script is using output-buffering-functions somewhere, then you have to clear the buffer
first ( with ob_clear() ), before outputting an image with a function like imagepng().
And you should make sure that no buffer will get send after outputing an image by using the
ob_end_flush()-function.
Furthermore you should check if a buffer has already been flushed somewhere before. This can be done
using the headers_sent()-function.
Here is the full solution:
==============
if(headers_sent()){
die('Headers have been send somewhere within my script');
}
ob_clean(); //Clears the buffer
header('Content-type: image/png');
imagepng($img, NULL, 0, NULL);
ob_end_flush(); //Now we send the header and image plus we make sure that nothing will get send from
now on (including possible shutdown-functions and __destruct()-methods) till the end of
page-execution
http://php.net/manual/en/book.image.php