views:

42

answers:

4

Background: We're using Google Charts to create graphs of some data generated by our web app. The user creates a report and then emails that report. Trouble is, once the user opens the report in Microsoft Word, that program exhibits some odd behavior regarding the dynamically generated images.

So, using PHP, we want to save our dynamically generated charts on the server, because Word can handle simple linked images without any problems.

I'm kind of at a loss on how to proceed. Ideas?

A: 

Just fetch the image using the URL your webfrontend is generating, then adjust the code which is generating the reports to include the images stored locally instead of the Google Chart URLs.

Any other problem?

halfdan
+1  A: 

you can use curl to fetch image and save it on the server:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://url.to.chart/");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FILE, '/path/to/file');
curl_exec($ch);
curl_close($ch);
ts
+2  A: 

The simplest way is probably to use something like curl to retrieve the image from Google and write it out to a file on your server. You could also just use fopen and related functions, if you turn on the allow_url_fopen option.

Amber
A: 
<?
$imageData = file_get_contents('http://chart.apis.google.com/chart... etc');

// Attach image data as attachment to an email
//OR: 

file_put_contents('/path/to/save/image.png',$imageData);
?>
Ollie