Hello,
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.

Thanks.

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

file_put_contents('images/imgs.png',$fp);

First you need a valid chart id, otherwise, even if you match one, it could be private and you won't be able to save it.

Then check this thread: http://www.daniweb.com/web-development/php/threads/256243
The solutions proposed there may save time for you, bye.

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

no

try:

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);
    $rawdata=curl_exec($ch);
    curl_close ($ch);
    if(file_exists($fullpath)){
        unlink($fullpath);
    }
    $fp = fopen($fullpath,'x');
    fwrite($fp, $rawdata);
    fclose($fp);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.