我有一個爲客戶端生成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
相關:http://stackoverflow.com/questions/697472/file-get-contents-returning-failed-to-open-stream-http-請求失敗 – Dogbert 2011-01-23 17:24:31