【问题标题】:Saving Google Chart image to file using PHP使用 PHP 将 Google 图表图像保存到文件
【发布时间】:2011-01-23 17:22:35
【问题描述】:

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

如果我尝试:

$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

该脚本适用于普通图像,但不适用于 Google 图表。如果我也使用 cURL 保存图像,结果相同。

下面是我的 Google 图表 $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

【问题讨论】:

标签: php charts


【解决方案1】:

CURL 示例:

<?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; ?>

【讨论】:

    【解决方案2】:

    我最终设法让它工作 - 似乎标签名称中的空格导致错误,用 %20 替换就可以了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-19
      • 1970-01-01
      • 2013-05-31
      • 2011-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多