示例#1
0
 function replace($photo, $photo_id, $async = null)
 {
     $upload_req = new HTTPRequest();
     $upload_req->setMethod("POST");
     $upload_req->setURL($this->Replace);
     //$upload_req->clearPostData();
     //Process arguments, including method and login data.
     $args = array("api_key" => $this->api_key, "photo_id" => $photo_id, "async" => $async);
     if (!empty($this->email)) {
         $args = array_merge($args, array("email" => $this->email));
     }
     if (!empty($this->password)) {
         $args = array_merge($args, array("password" => $this->password));
     }
     if (!empty($this->token)) {
         $args = array_merge($args, array("auth_token" => $this->token));
     } elseif (!empty($_SESSION['phpFlickr_auth_token'])) {
         $args = array_merge($args, array("auth_token" => $_SESSION['phpFlickr_auth_token']));
     }
     ksort($args);
     $auth_sig = "";
     foreach ($args as $key => $data) {
         if ($data !== null) {
             $auth_sig .= $key . $data;
             $upload_req->addPostData($key, $data);
         }
     }
     if (!empty($this->secret)) {
         $api_sig = md5($this->secret . $auth_sig);
         $upload_req->addPostData("api_sig", $api_sig);
     }
     $photo = realpath($photo);
     $result = $upload_req->addFile("photo", $photo);
     //Send Requests
     if ($upload_req->sendRequest()) {
         $this->response = $upload_req->getResponseBody();
     } else {
         die("There has been a problem sending your command to the server.");
     }
     if ($async == 1) {
         $find = 'ticketid';
     } else {
         $find = 'photoid';
     }
     $rsp = explode("\n", $this->response);
     foreach ($rsp as $line) {
         if (ereg('<err code="([0-9]+)" msg="(.*)"', $line, $match)) {
             if ($this->die_on_error) {
                 die("The Flickr API returned the following error: #{$match[1]} - {$match[2]}");
             } else {
                 $this->error_code = $match[1];
                 $this->error_msg = $match[2];
                 $this->parsed_response = false;
                 return false;
             }
         } elseif (ereg("<" . $find . ">(.*)</", $line, $match)) {
             $this->error_code = false;
             $this->error_msg = false;
             return $match[1];
         }
     }
 }