0

here's a portion of my code (taken from google charts example here http://code.google.com/apis/chart/image/docs/post_requests.html) that will display an image chart:

 $context = stream_context_create(
array('http' => array(
  'method' => 'POST',
  'content' => http_build_query($chart))));
fpassthru(fopen($url, 'r', false, $context));

The problem is instead of displaying the image directly, I'd like to pass the contents of fpassthru (which essentially is the image) to a variable.. perhaps something like

$image = fpassthru(fopen($url, 'r', false, $context));

any idea? thanks

imin
  • 4,504
  • 13
  • 56
  • 103

1 Answers1

4

Use file_get_contents:

$image = file_get_contents($url, false, $context);

or stream_get_contents (but don't forget to close the file):

$f = fopen($url, 'rb', false, $context);
$image = stream_get_contents($f);
fclose($f);
Akira Yamamoto
  • 4,685
  • 4
  • 42
  • 43
phihag
  • 278,196
  • 72
  • 453
  • 469