本文整理汇总了PHP中HTTPRequest::addFile方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTPRequest::addFile方法的具体用法?PHP HTTPRequest::addFile怎么用?PHP HTTPRequest::addFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPRequest
的用法示例。
在下文中一共展示了HTTPRequest::addFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: replace
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];
}
}
}