本文整理汇总了PHP中HTTP_Request::addFile方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP_Request::addFile方法的具体用法?PHP HTTP_Request::addFile怎么用?PHP HTTP_Request::addFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTP_Request
的用法示例。
在下文中一共展示了HTTP_Request::addFile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRequestInstance
function getRequestInstance($url, $http_verb = 'GET', $options = array(), $body = '')
{
$default_options = array('header' => array(), 'params' => array());
$options = array_merge($default_options, $options);
$options['header']['user-agent'] = empty($options['header']['user-agent']) ? 'Akelos PHP Framework AkHttpClient (http://akelos.org)' : $options['header']['user-agent'];
list($user_name, $password) = $this->_extractUserNameAndPasswordFromUrl($url);
require_once AK_VENDOR_DIR . DS . 'pear' . DS . 'HTTP' . DS . 'Request.php';
$this->{'_setParamsFor' . ucfirst(strtolower($http_verb))}($url, $options['params']);
$this->HttpRequest =& new HTTP_Request($url);
$user_name ? $this->HttpRequest->setBasicAuth($user_name, $password) : null;
$this->HttpRequest->setMethod(constant('HTTP_REQUEST_METHOD_' . $http_verb));
if ($http_verb == 'PUT' && !empty($options['params'])) {
$this->setBody(http_build_query($options['params']));
}
if (!empty($body)) {
$this->setBody($body);
}
if (!empty($options['file'])) {
$this->HttpRequest->addFile($options['file']['inputname'], $options['file']['filename']);
}
!empty($options['params']) && $this->addParams($options['params']);
$this->addHeaders($options['header']);
return $this->HttpRequest;
}
示例2: post
function post($img_index)
{
global $image_files;
$url = 'http://twitter.com/account/update_profile_image.json';
$file_name = $image_files[$img_index];
if (!file_exists($file_name)) {
result('画像ファイル名が不正です。');
}
$pathinfo = pathinfo($file_name);
$extension = strtolower($pathinfo['extension']);
switch ($extension) {
case 'png':
case 'gif':
// do nothing.
break;
case 'jpeg':
case 'jpg':
$extension = 'jpg';
break;
default:
result('画像の拡張子が不正です。');
}
$request = new HTTP_Request($url);
$request->setMethod(HTTP_REQUEST_METHOD_POST);
$request->setBasicAuth(USERNAME, PASSWORD);
$result = $request->addFile('image', $file_name, "image/{$extension}");
if (PEAR::isError($result)) {
result($result->getMessager());
}
$response = $request->sendRequest();
if (PEAR::isError($response)) {
result($response->getMessage());
}
$body = $request->getResponseBody();
return true;
}
示例3: request
static function request($method, $url, $token = null, $params = array(), $file = null)
{
$req = new HTTP_Request($url);
$req->setMethod($method == "get" ? HTTP_REQUEST_METHOD_GET : HTTP_REQUEST_METHOD_POST);
$req->addHeader("X-Gallery-Request-Method", $method);
if ($token) {
$req->addHeader("X-Gallery-Request-Key", $token);
}
foreach ($params as $key => $value) {
$req->addPostData($key, $value);
}
if ($file) {
$req->addFile("file", $file, mime_content_type($file));
}
$req->sendRequest();
switch ($req->getResponseCode()) {
case 200:
return json_decode($req->getResponseBody());
case 403:
throw new Gallery3_Forbidden_Exception($req->getResponseBody());
default:
throw new Gallery3_Exception($req->getResponseBody());
}
}
示例4: callMethod
/**
* callMethod
*
* @access private
* @param string $method_name
* @param array $send_param
* @param string $method
* @return string result XML data
*/
private function callMethod($method_name, $send_param = array(), $method = 'post')
{
$request = new HTTP_Request($this->api_url . $method_name);
$request->setBasicAuth($this->username, $this->password);
if ($method == "post") {
$request->setMethod(HTTP_REQUEST_METHOD_POST);
}
if (count($send_param) != 0) {
foreach ($send_param as $key => $value) {
if ($key == "photo" && $method_name == "photo_add") {
$request->addFile($key, $value, $this->getMime($value));
} else {
if ($method == "post") {
$request->addPostData($key, $value, true);
} else {
$request->addQueryString($key, $value, true);
}
}
}
}
$response = $request->sendRequest();
if (PEAR::isError($response)) {
return $response;
} else {
$body = $request->getResponseBody();
if (strpos($body, 'rsp stat="fail"') !== false) {
preg_match('|err code="(.*?)" msg="(.*?)"|', $body, $matches);
$code = 0;
if (isset($this->error_code[$matches[1]])) {
$code = $this->error_code[$matches[1]];
}
return PEAR::raiseError($matches[1] . ':' . $matches[2], $code);
} else {
return $body;
}
}
}
示例5: export_datas_to_repo
function export_datas_to_repo()
{
$file = "/etc/artica-postfix/smtp.hacks.export.db";
if (!is_file($file)) {
echo "{$file} no such file\n";
return;
}
include_once "HTTP/Request.php";
$ini = new Bs_IniHandler();
$sock = new sockets();
$datas = $sock->GET_INFO("ArticaProxySettings");
$ini->loadString($datas);
$ArticaProxyServerEnabled = $ini->_params["PROXY"]["ArticaProxyServerEnabled"];
$ArticaProxyServerName = $ini->_params["PROXY"]["ArticaProxyServerName"];
$ArticaProxyServerPort = $ini->_params["PROXY"]["ArticaProxyServerPort"];
$ArticaProxyServerUsername = $ini->_params["PROXY"]["ArticaProxyServerUsername"];
$ArticaProxyServerUserPassword = $ini->_params["PROXY"]["ArticaProxyServerUserPassword"];
$req = new HTTP_Request("http://www.articatech.net/smtphack-import.php");
$req->setURL("http://www.articatech.net/smtphack-import.php");
$req->setMethod('POST');
if ($ArticaProxyServerEnabled == "yes") {
$req->setProxy($ArticaProxyServerName, $ArticaProxyServerPort, $ArticaProxyServerUsername, $ArticaProxyServerUserPassword);
}
$req->addPostData('xyz', time());
$result = $req->addFile('smtp-hack-file', $file, 'multipart/form-data');
// $req->sendRequest();
if (PEAR::isError($result)) {
echo $result->getMessage();
} else {
$response = $req->sendRequest();
if (PEAR::isError($response)) {
echo $response->getMessage();
return false;
}
if (preg_match("#SUCCESS#", $req->getResponseBody())) {
if ($GLOBALS["DEBUG"]) {
echo "Central server success\n" . $req->getResponseBody() . "\n";
}
return true;
}
if ($GLOBALS["DEBUG"]) {
echo "Central server failed\n" . $req->getResponseBody() . "\n";
}
}
}
示例6: replace
function replace ($photo, $photo_id, $async = null) {
$upload_req = new HTTP_Request();
$upload_req->setMethod(HTTP_REQUEST_METHOD_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);
if (PEAR::isError($result)) {
die($result->getMessage());
}
//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];
}
}
}