php中用get方式获取网络资源内容

php中用get方式获取网络资源内容

<?php
$photo  = 'http://www.xxx.com/uploads/5908618d80559a594164d984c5ca2b01_32.png';
if ($photo) {
        $http = new HttpRequest($photo, HTTP_METH_GET);
        try {
                $http->send();
        } catch(Exception $e) {
                try {
                        $http->send();
                } catch (Exception $e) {
                        try {
                                $http->send();
                        } catch (Exception $e) {
                                echo 'error occured while loading file.';
                                exit;
                        }
                }
        }
        if ($http->getResponseCode() == 200) {
                $header = $http->getResponseHeader();
                if (strstr($header['Content-Type'], 'image') !== FALSE) {
                     echo base64_encode($http->getResponseBody());
                }
        }
}
?>

你可能感兴趣的:(php中用get方式获取网络资源内容)