0

私のアプリケーションはGoogleChartsとHTTPSを使用しています。Googleチャートを「安全な」画像として表示する必要があります。そうしないと、InternetExplorerが安全でないコンテンツの表示について文句を言います。そこで、Zend_Http_Clientリクエストを使ってダウンロード(ローカルファイルへのリンク)しようとしていますが、できないようです。

このリンクをクリックして画像を表示できるため、URIは有効である必要があります。

http://chart.apis.google.com/chart?chs=250x150&cht=bvg&chds=0,19&chd=t:19&chxt=x,y&chxl=0:|2009&chxr=1,0,19&chf=bg,s,F2F0E1

これが私が使用しているコードです:

$chartUrl = 'http://chart.apis.google.com/chart?chs=250x150&cht=bvg&chds=0,19&chd=t:19&chxt=x,y&chxl=0:|2009&chxr=1,0,19&chf=bg,s,F2F0E1';
$client = new Zend_Http_Client($chartUrl, array('maxredirects' => 0, 'timeout' => 30));
$response = $client->request();

私は何が間違っているのですか?これを達成する別の方法はありますか?

回避策

Google Chart URIは「無効な」文字を使用しているため、を作成するときに検証に失敗しますZend_Uri。これは、GoogleChartをダウンロードするために私がしなければならなかったことです。

/**
 * Returns the URL of the Google chart image that has been downloaded and stored locally. If it has not been downloaded yet, it will be download.
 * @param string $chartUrl
 * @return string
 */
protected function _getLocalImageUrl($chartUrl)
{
    $savePath = realpath(APPLICATION_PATH . '/../public/Resources/google-charts/');
    $hashedChartUrl = md5($chartUrl);
    $localPath = "$savePath/$hashedChartUrl";
    
    if (!file_exists($localPath)) {
        exec("wget -O \"$localPath\" \"$chartUrl\"");
    }
    
    return "/Resources/google-charts/$hashedChartUrl";
}
4

1 に答える 1

0

試す:$chartUrl = 'http://chart.apis.google.com/chart?chs=250x150&cht=bvg&chds=0,19&chd=t%3A19&chxt=x,y&chxl=0%3A|2009&chxr=1,0,19&chf=bg,s,F2F0E1';

[編集]コメントで述べたように、urlencodeは問題を修正しませんでしたが、コロンを16進値に置き換えると修正されました。

于 2010-08-16T16:18:23.313 に答える