Got it working using this:
$ch = curl_init('http://chart.apis.google.com/chart?
chid='.md5(uniqid(rand(), true)).'&'.http_build_query($chart));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_POST,count($chart));
curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($chart));
$response = curl_exec($ch);
$file = fopen($filename, 'w+');
fwrite($file, $response);
fclose($file);
Just put all the params into the chart array.
On Oct 6, 4:26 pm, trk247 <[email protected]> wrote:
> I'm trying to save a chart via PHP on my server. The image gets
> saved, but it says it cannot be displayed because of errors. It also
> renders fine in the browser.
>
> Any help appreciated.
>
> Here is my code:
>
> function saveImage($chart_url,$local_image_path,$image_name) {
> //initialize curl
> $ch = curl_init($chart_url);
> //open file to write image to
> $fp = fopen($local_image_path.$image_name, "wb");
>
> // set URL and other appropriate options
> $options = array(CURLOPT_FILE => $fp,
> CURLOPT_HEADER => 0,
> CURLOPT_FOLLOWLOCATION => 1,
> CURLOPT_TIMEOUT => 60);
>
> curl_setopt_array($ch, $options);
> //get the image
> curl_exec($ch);
> //close the connection
> curl_close($ch);
> //finish writing to the file
> fclose($fp);}
>
> $local_image_path = 'cache/';
> $image_name = 'some_chart_image.png';
>
> $chart_url = 'http://chart.apis.google.com/chart?cht=lc&chls=3,6,3|
> 1,1,0&chco=67bd4b&chf=bg,s,efefef|c,lg,ddffd3,1,ffffff,0&chm=h,67bd4b,
> 1,7.0,1.0|B,ddffd3,1,0,0&chd=t:-1|
> 50,50,50,50,50,50,50,100,50,50,50,50&chxt=x,y&chxl=0:|Sept 1|Sept 15|
> Sept 30|1:|0|1|2&chxp=0,Sept 1,Sept 15,Sept 30|
> 1,0,1,2&chxr=1,0,2&chtt=Actions&chs=300x200';
>
> saveImage($chart_url, $local_image_path, $image_name);
--
You received this message because you are subscribed to the Google Groups
"Google Chart API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-chart-api?hl=en.