how can i load a full image in variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bugthefixer
Forum Contributor
Posts: 118
Joined: Mon Mar 22, 2004 2:35 am

how can i load a full image in variable

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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...
?>
Post Reply