-3

我有以下代码

class Flickr { 
    private $apiKey = 'YOUR API KEY HERE'; 

    public function __construct() {
    } 

    public function search($query = null) { 
        $search = 'http://flickr.com/services/rest/?method=flickr.photos.search&api_key=' . $this->apiKey . '&text=' . urlencode($query) . '&per_page=50&format=php_serial'; 
        $result = file_get_contents($search); 
        $result = unserialize($result); 
        return $result; 
    } 
}

我的虚拟主机不允许我使用 file_get_contents。我怎样才能使用 curl 代替?

4

1 回答 1

0

Something like this

<?php
    class Flickr { 
    private $apiKey = 'YOUR API KEY HERE'; 

    public function __construct() {
    } 

    public function search($query = null) {
    $url = 'http://flickr.com/services/rest/?method=flickr.photos.search&api_key=' . $this->apiKey . '&text=' . urlencode($query) . '&per_page=50&format=php_serial';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL,$url);
    $result=curl_exec($ch);
    //echo $result;//Your response
    return $result;
    }
  }
于 2013-11-02T08:34:38.557 回答