2011-01-23 109 views
1

我有一个为客户端生成Google图表图像的脚本。它可以在HTML中正常显示,但我现在需要将每个图表保存为.png。使用PHP将Google图表图像保存为文件

如果我尝试:

$imageData = file_get_contents($url); file_put_contents('C:/xampp/htdocs/image.png',$imageData);

然后我总是收到

[function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 

该脚本工作正常,正常图像,而不是谷歌的图表。如果我使用cURL来保存图像,结果也是相同的。

我的Google chart $ url的示例如下。我诅咒了冒号和管道符号,但它并没有解决这个问题:

http://chart.apis.google.com/chart?cht=lc&chxt=x,y&chs=700x400&chco=76A4FB,FF9900&chg=0,8.3333333&chdl=Visits|Unique%20visits&chls=3|3&chma=40,20,20,30&chxr=1,0,33411&chds=0,33411&chd=t%3A33411,33411,33411,33411,33411,33411,33411,33411,33411,33411,33411,33411|33411,33411,33411,33411,33411,33411,33411,33411,33411,33411,33411,33411&chxl=0%3A|Jan-10|Feb-10|Mar-10|Apr-10|May-10|Jun-10|Jul-10|Aug-10|Sep-10|Oct-10|Nov-10|Dec-10 
+0

相关:http://stackoverflow.com/questions/697472/file-get-contents-returning-failed-to-open-stream-http-请求失败 – Dogbert 2011-01-23 17:24:31

回答

0

我设法得到这个工作进行到底 - 这似乎在标签名称中的空格都导致错误,与更换%20的伎俩

1

卷曲例如:

<?php 
    $ch = curl_init("www.example.com/curl.php?option=test"); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $output = curl_exec($ch);  
    curl_close($ch); 
    echo $output; ?>