facebook twitter hatena line email

Php/zend framework/ウェブ上の画像をバイナリ表示

提供: 初心者エンジニアの簡易メモ
2015年5月20日 (水) 03:18時点における127.0.0.1 (トーク)による版 (ページの作成:「 <?php require_once 'Zend/Http/Client.php'; require_once 'Zend/Http/Client/Adapter/Exception.php'; /** * ウェブ上の画像を取得し表示する * @ex * $h...」)

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)
移動: 案内検索
<?php
require_once 'Zend/Http/Client.php';
require_once 'Zend/Http/Client/Adapter/Exception.php';
/**
 * ウェブ上の画像を取得し表示する
 * @ex
 * $http = new Model_Httpbinary();
 * $http->printBinary();
 */
class Model_Httpbinary
{
    private $_response;
    public function request($url)
    {
        // Http_Clientロード
        $client = new Zend_Http_Client();
        try {
            $client->setUri($url);
            $client->setConfig(array(
             'maxredirects' => 5,
             'timeout' => 30
            ));
        //>-$params = array("id" => "hoge", "pass" => "hoge");
            // GET 複数のパラメータを一度に追加します
        //>-$client->setParameterGet($params);
            // GET リクエストを実行します
            $this->_response = $client->request();
        } catch (Zend_Http_Client_Adapter_Exception $e) {
            // handle the error
            error_log($e);
        }
    }
    public function printBinary()
    {
        header('Content-Type:'. $this->_response->getHeader(Zend_HTTP_Client::CONTENT_TYPE));
        echo $this->_response->getBody();
    }
    public function getBinary()
    {
        return $this->_response->getBody();
    }
}