Page 1 of 1

how can i load a full image in variable

Posted: Fri Jun 18, 2004 2:57 am
by bugthefixer
i want to load a full imge in some sort of variable that i can pass to java applet..how can i do that

Posted: Fri Jun 18, 2004 3:21 am
by feyd
if the file already exists:

Code: Select all

<?php

$data = file_get_contents('/path/to/the/file.jpg');

?>
as for using dynamic images created by php..
php manual, user comment wrote:Rather than using the temporary file, as described above, you can buffer the output stream. Someone else showed me this, and it seems to work very nicely.

Code: Select all

<?php
   //Start buffering the output stream
   ob_start();

   // output the image as a file to the output stream
   Imagejpeg($im);
   
   //Read the output buffer
   $buffer = ob_get_contents();

   //clear the buffer
   ob_end_clean();

   //use $buffer as you wish...
?>