Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
can someone explain to me what ob_start() does? I have a vague idea its got something to do with buffering output.
i've seen it in all dynamic image creation scripts, so i figured i might as well use it, but i want to know why!
how and why is it used in this example...
header("Content-Type: image/jpeg");
$imageData = <get image data from database>
<resizing etc>
$src = imagecreatefromstring($imageData);
$img = imagecreatetruecolor($new_w,$new_h);
imagecopyresized($img,$src,0,0,0,0,$new_w,$new_h,$w,$h);ob_start();
imagejpeg($img);
ob_end_flush();
imagedestroy($img);
thanks for the info...

Simple. ob_start() opens a buffer and pipes all script output into the buffer. The typical script output is text (e.g. from echo statements).
In the example you cite, an image is being created and printed directly to output (imagejpeg() does that when no file path is specified). Since the buffer is opened before imagejpeg() is called, the image goes into the buffer. Of course, flushing the buffer gets rid of this. Regardless, that is what the code is doing.

![]() |
Microsoft Access Joins
|
Manipulating componf term...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |