in process.php, I am trying to display google chart by requesting it using streams, the follwoing code is for requesting the chart:

header('content-type: image/png');
  $url = 'https://chart.googleapis.com/chart?chid=' . md5(uniqid(rand(), true));
  $chd = 't:';
  for ($i = 0; $i < 150; ++$i) {
    $data = rand(0, 100000);
    $chd .= $data . ',';
  $chd = substr($chd, 0, -1);

  // Add data, chart type, chart size, and scale to params.
  $chart = array(
    'cht' => 'lc',
    'chs' => '600x200',
    'chds' => '0,100000',
    'chd' => $chd);

  // Send the request, and print out the returned bytes.
$context = stream_context_create(
    array('http' => array(
      'method' => 'POST',
      'content' => http_build_query($chart))));
$fp=fopen($url, 'r', false, $context);

How can I save the chart as .png inside a file called images then pass the name of the file back to index.php.


Well I am just testing trying to undersatnd how to get a google chart and save it as .png inside a folder, I tried this but I got invalid image saved, I run my code on wamp


still not working :(

any ideas how to get the image from the file pointer and save it?

if not with stream, dose any one have a n idea of saving an image using curl?

still not working


function save_image($img,$fullpath){
    $ch = curl_init ($img);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
    curl_close ($ch);
    $fp = fopen($fullpath,'x');
    fwrite($fp, $rawdata);