当前位置: 首页>>代码示例>>PHP>>正文


PHP HTTP_Request::addFile方法代码示例

本文整理汇总了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;
 }
开发者ID:joeymetal,项目名称:v1,代码行数:24,代码来源:AkHttpClient.php

示例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;
}
开发者ID:kwappa,项目名称:twicoro,代码行数:36,代码来源:change.php

示例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());
     }
 }
开发者ID:ady1503,项目名称:gallery3-contrib,代码行数:24,代码来源:Gallery3.php

示例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;
         }
     }
 }
开发者ID:rsky,项目名称:tweetie2photozou,代码行数:46,代码来源:Photozou.php

示例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";
        }
    }
}
开发者ID:BillTheBest,项目名称:1.6.x,代码行数:45,代码来源:exec.smtp-hack.export.php

示例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];
			}
		}
	}
开发者ID:rkern21,项目名称:videoeditor,代码行数:71,代码来源:phpFlickr5.php


注:本文中的HTTP_Request::addFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。