开发者

pass fpassthru contents to variable

开发者 https://www.devze.com 2023-03-22 08:04 出处:网络
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:

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', f开发者_开发技巧alse, $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


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消