本文整理汇总了PHP中http_class类的典型用法代码示例。如果您正苦于以下问题:PHP http_class类的具体用法?PHP http_class怎么用?PHP http_class使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了http_class类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: http_adv_get
function http_adv_get($qtype, $url, $extra = array(), $headers = array())
{
$http = new http_class();
$http->debug = 0;
$http->html_debug = 0;
$http->request_method = $qtype;
$http->GetRequestArguments($url, $args);
$err = $http->Open($args);
foreach ($extra as $key => $value) {
$args[$key] = $value;
}
$body = "";
foreach ($headers as $key => $value) {
$args['Headers'][$key] = $value;
}
if ($err == "") {
$err = $http->Open($args);
$err = $http->SendRequest($args);
$http->ReadReplyHeaders($headers);
if ($err == "") {
if ($err == "") {
for (;;) {
$err = $http->ReadReplyBody($acc, 2000);
if ($err != "" || $acc == "") {
break;
}
$body .= $acc;
}
}
}
$http->close();
}
return array($headers, $body);
}
示例2: _checkSFS
function _checkSFS($username, $email, $ip = '')
{
global $_TABLES, $_SPX_CONF, $LANG_SX00;
$rc = 0;
$arguments = array();
$response = '';
$http = new http_class();
$http->timeout = 0;
$http->data_timeout = 0;
$http->debug = 0;
$http->html_debug = 0;
$http->user_agent = 'glFusion/' . GVERSION;
$url = "http://www.stopforumspam.com/api";
$requestArgs = '?f=serial&';
if ($ip != '') {
$requestArgs .= 'ip=' . $ip . '&';
}
if ($email != '') {
$requestArgs .= 'email=' . urlencode($email) . '&';
}
if ($username != '') {
$requestArgs .= 'username=' . urlencode($username) . '&';
}
$requestArgs .= 'cmd=display';
$url = $url . $requestArgs;
$error = $http->GetRequestArguments($url, $arguments);
$error = $http->Open($arguments);
$error = $http->SendRequest($arguments);
if ($error == "") {
$error = $http->ReadReplyBody($body, 1024);
if ($error != "" || strlen($body) == 0) {
break;
}
$response = $response . $body;
$result = @unserialize($response);
if (!$result) {
return 0;
}
// invalid data, assume ok
if (isset($result['email']) && $result['email']['appears'] == 1) {
$rc = $rc + 1;
}
if (isset($result['ip']) && $result['ip']['appears'] == 1) {
$rc = $rc + 2;
}
if (isset($result['username']) && $result['username']['appears'] == 1) {
$rc = $rc + 4;
}
}
return $rc;
}
示例3: send_request
public function send_request($request)
{
$response_code = '0';
$response_info = array();
$response_headers = array();
$error = '';
$http = new http_class();
$http->follow_redirect = 1;
$http->redirection_limit = 5;
$http->prefer_curl = 0;
$error = $http->GetRequestArguments($request->uri, $arguments);
if ($request->credentials != null) {
$http->authentication_mechanism = "Digest";
$arguments['AuthUser'] = $request->credentials->get_username();
$arguments['AuthPassword'] = $request->credentials->get_password();
}
$arguments["RequestMethod"] = $request->method;
foreach ($request->headers as $k => $v) {
$arguments["Headers"][$k] = $v;
}
if ($request->body != null) {
$arguments["Body"] = $request->body;
}
$error = $http->Open($arguments);
if (!$error) {
$error = $http->SendRequest($arguments);
}
if (!$error) {
$error = $http->ReadReplyHeaders($response_headers);
$response_code = $http->response_status;
$response_body = '';
for (;;) {
$error = $http->ReadReplyBody($body, 1000);
if ($error != "" || strlen($body) == 0) {
break;
}
$response_body .= $body;
}
} else {
if ($request->_cache && $cached_response) {
return $cached_response;
}
$response_body = "Request failed: " . $error;
}
$http->Close();
$response = new HttpResponse();
$response->status_code = $response_code;
$response->headers = $response_headers;
$response->body = $response_body;
$response->info = $response_info;
//ID20100317 $response->request = $request;
$response->request_method = $request->method;
$response->request_uri = $request->uri;
$response->request_headers = $request->headers;
$response->request_body = $request->body;
$key = spl_object_hash($request);
$this->responses[$key] = $response;
return $key;
}
示例4: get
/**
* Fetch a remote URI then return results.
*
* If this method is triggered without the second parameter, <b>$target</b>, then
* result will be return in the following format:
*
* <pre>array(
* 'header' => array(
* 'header_1' => 'header_value_1',
* 'header_2' => 'header_value_2',
* etc...
* ),
* 'body' => 'fetched response body'
* )</pre>
*
* Otherwise, the fetched response body will be saved to the local file specified
* by the variable <b>$target</b>. The example below will download the remote image
* <b>http://placehold.it/300x200.gif</b> then save to the local file
* <b>/tmp/downloaded_image.gif</b>:
*
* <pre>JSNUtilsHttp::get(
* 'http://placehold.it/300x200.gif',
* '/tmp/downloaded_image.gif'
* );</pre>
*
* When the second parameter is set in method call, the method will always return
* the boolean value <b>true</b> if file is successfully saved or <b>false</b>
* if file is not saved.
*
* @param string $uri Remote URI for fetching content.
* @param string $target Set to a file path to save fetched content as local file.
* @param boolean $validateHeader Check for 200 OK header or not?
*
* @return array array('header' => 'Associative array of fetched header', 'body' => 'Fetched content')
*/
public static function get($uri, $target = '', $validateHeader = false)
{
// Preset return result
$result = array();
// Initialize HTTP client
$http = new http_class();
$http->follow_redirect = 1;
$http->redirection_limit = 5;
$http->GetRequestArguments($uri, $arguments);
// Open connection
if (($error = $http->Open($arguments)) == '') {
if (($error = $http->SendRequest($arguments)) == '') {
// Get response header
$header = array();
if (($error = $http->ReadReplyHeaders($header)) != '') {
throw new Exception(JText::sprintf('JSN_EXTFW_HTTP_CONNECTION_ERROR', $error));
}
$result['header'] = $header;
// Validate header
if ($validateHeader) {
foreach ($result['header'] as $header => $value) {
if (strtolower(substr($header, 0, 5)) == 'http/' and strpos($header, '200') === false) {
throw new Exception(JText::sprintf('JSN_EXTFW_HTTP_CONNECTION_ERROR', substr($header, strpos($header, ' '))));
}
}
}
// Get response body
$result['body'] = '';
while (true) {
if (($error = $http->ReadReplyBody($body, 1000)) != '' or strlen($body) == 0) {
break;
}
$result['body'] .= $body;
}
} else {
throw new Exception(JText::sprintf('JSN_EXTFW_HTTP_CONNECTION_ERROR', $error));
}
// Close connection
$http->Close();
} else {
throw new Exception(JText::sprintf('JSN_EXTFW_HTTP_CONNECTION_ERROR', $error));
}
return !empty($target) ? JFile::write($target, $result['body']) : $result;
}
示例5: doHeadRequest
/**
* Send an HTTP HEAD request for the given URL
*
* @param string $url URL to request
* @param string $errmsg error message, if any (on return)
* @return int HTTP response code or 777 on error
*
*/
function doHeadRequest($url, &$errmsg)
{
$http = new http_class();
$http->timeout = 0;
$http->data_timeout = 0;
$http->debug = 0;
$http->html_debug = 0;
$http->user_agent = 'glFusion/' . GVERSION;
$error = $http->GetRequestArguments($url, $arguments);
$error = $http->Open($arguments);
$error = $http->SendRequest($arguments);
if ($error == "") {
$http->ReadReplyHeaders($headers);
return $http->response_status;
} else {
$errmsg = $error;
return 777;
}
}
示例6: CheckForSpam
/**
* Check for spam links
*
* @param string $post post to check for spam
* @return boolean true = spam found, false = no spam
*
* Note: Also returns 'false' in case of problems communicating with SFS.
* Error messages are logged in glFusion's error.log
*
*/
function CheckForSpam($post)
{
global $_SPX_CONF, $REMOTE_ADDR;
$retval = false;
$ip = $REMOTE_ADDR;
if (empty($post) || $ip == '') {
return $retval;
}
$arguments = array();
$response = '';
$http = new http_class();
$http->timeout = 0;
$http->data_timeout = 0;
$http->debug = 0;
$http->html_debug = 0;
$http->user_agent = 'glFusion/' . GVERSION;
$url = "http://www.stopforumspam.com/api";
$requestArgs = '?f=serial&';
if ($ip != '') {
$requestArgs .= 'ip=' . $ip . '&';
}
$requestArgs .= 'cmd=display';
$url = $url . $requestArgs;
$error = $http->GetRequestArguments($url, $arguments);
$error = $http->Open($arguments);
$error = $http->SendRequest($arguments);
if ($error == "") {
$error = $http->ReadReplyBody($body, 1024);
if ($error == "" || strlen($body) > 0) {
$response = $response . $body;
$result = @unserialize($response);
if (!$result) {
return 0;
}
// invalid data, assume ok
if (isset($result['ip']) && $result['ip']['appears'] == 1 && $result['ip']['confidence'] > (double) 25) {
$retval = true;
SPAMX_log("SFS: spam detected");
}
}
}
return $retval;
}
示例7: PNB_getPingbackUrl
/**
* Get the Pingback URL for a given URL
*
* @param string $url URL to get the Pingback URL for
* @return string Pingback URL or empty string
*/
function PNB_getPingbackUrl($url)
{
$retval = '';
$http = new http_class();
$http->timeout = 0;
$http->data_timeout = 0;
$http->debug = 0;
$http->html_debug = 0;
$http->user_agent = 'glFusion/' . GVERSION;
$error = $http->GetRequestArguments($url, $arguments);
$error = $http->Open($arguments);
$error = $http->SendRequest($arguments);
if ($error == "") {
$http->ReadReplyHeaders($headers);
if (isset($headers['x-pingback'])) {
$retval = $headers['x-pingback'];
} else {
COM_errorLog("Pingback (HEAD): unable to locate x-pingback header");
}
} else {
COM_errorLog('Pingback (HEAD): ' . $error);
return false;
}
if (empty($retval)) {
// search for <link rel="pingback">
$http = new http_class();
$http->timeout = 0;
$http->data_timeout = 0;
$http->debug = 0;
$http->html_debug = 0;
$http->user_agent = 'glFusion/' . GVERSION;
$error = $http->GetRequestArguments($url, $arguments);
$error = $http->Open($arguments);
$error = $http->SendRequest($arguments);
if ($error == "") {
$http->ReadReplyHeaders($headers);
if ($http->response_status == 200) {
$error = $http->ReadWholeReplyBody($body);
if ($error != "" && strlen($body) === 0) {
COM_errorLog("Pingback (GET): unable to retrieve response body");
return false;
}
} else {
COM_errorLog("Pingback (GET): Got HTTP response code " . $http->response_status . " when requesting " . $url);
return false;
}
} else {
COM_errorLog("Pingback (GET): " . $error . " when requesting " . $url);
return false;
}
// only search for the first match - it doesn't make sense to have
// more than one pingback URL
$found = preg_match("/<link rel=\"pingback\"[^>]*href=[\"']([^\"']*)[\"'][^>]*>/i", $body, $matches);
if ($found === 1 && !empty($matches[1])) {
$url = str_replace('&', '&', $matches[1]);
$retval = urldecode($url);
}
}
return $retval;
}
示例8: open_url
function open_url($type, $params = array())
{
$http = new http_class();
$http->request_method = 'POST';
$http->user_agent = "cesar-rodas/1.0 | Akismet-Class/" . CLASS_VERSION;
$http->follow_redirect = 1;
$http->redirection_limit = 5;
$http->exclude_address = "";
$http->protocol_version = "1.1";
$http->GetRequestArguments($this->get_url($type), $arguments);
$arguments['PostValues'] = $params;
$this->err = $http->Open($arguments);
if ($this->err != "") {
return false;
}
$this->err = $http->SendRequest($arguments);
if ($this->err != "") {
return false;
}
$this->err = $http->ReadReplyHeaders($gHeaders);
if ($this->err != "") {
return false;
}
if ($http->response_status != 200) {
$this->err = "Pages status: " . $http->response_status;
$http->Close();
return false;
}
$response = '';
for (;;) {
$this->error = $http->ReadReplyBody($body, 1000);
if ($this->error != "" || strlen($body) == 0) {
break;
}
$response .= $body;
}
$http->close();
return $response;
}
示例9: httpClientPost
function httpClientPost($url, $paramters)
{
//$url='https://login.yahoo.com/config/login?';
//$url="https://accounts.google.com/ServiceLogin";
//log echo '<br/> httpClient $url: '. $url ;
//log echo '<br/> httpClient $paramters: ' ;
//log var_dump($paramters);
$resultbody;
set_time_limit(0);
$http = new http_class();
$http->timeout = 0;
$http->data_timeout = 0;
$http->debug = 0;
$http->html_debug = 1;
//$url="https://login.yahoo.com/config/login";
if ($this->isDebug) {
echo "<br/>url:" . $url;
echo "<br/>arguments:<br/>";
var_dump($paramters);
}
$error = $http->GetRequestArguments($url, $arguments);
$arguments["RequestMethod"] = "POST";
//$arguments['Protocol']='https';
//$arguments['HostName']='login.yahoo.com';
//$arguments['HostPort']='443';
//$arguments['RequestMethod']='POST';
$arguments['PostValues'] = $paramters;
/*
$arguments["PostValues"]=array(
"somefield"=>"Upload forms",
"MAX_FILE_SIZE"=>"1000000"
);
$arguments["PostFiles"]=array(
"userfile"=>array(
"Data"=>"This is just a plain text attachment file named attachment.txt .",
"Name"=>"attachment.txt",
"Content-Type"=>"automatic/name",
),
"anotherfile"=>array(
"FileName"=>"test_http_post.php",
"Content-Type"=>"automatic/name",
)
);
$arguments["Referer"]="http://www.alltheweb.com/";
*/
if ($this->isDebug) {
echo "<H2><LI>Opening connection to:</H2>\n<PRE>", HtmlEntities($arguments["HostName"]), "</PRE>\n";
echo '<br/> <b>$arguments: </b><br/> ';
var_dump($arguments);
}
flush();
$error = $http->Open($arguments);
if ($this->isDebug) {
echo "<br/><br/>http->open:" . $error . "<br/>";
}
if ($error == "") {
$error = $http->SendRequest($arguments);
if ($this->isDebug) {
echo "<br/>[http->SendRequest:" . $error . "]<br/><br/>";
}
if ($error == "") {
//log echo "<H2><LI>Request:</LI</H2>\n<PRE>\n".HtmlEntities($http->request)."</PRE>\n";
//log echo "<H2><LI>Request headers:</LI</H2>\n<PRE>\n";
for (Reset($http->request_headers), $header = 0; $header < count($http->request_headers); Next($http->request_headers), $header++) {
$header_name = Key($http->request_headers);
if (GetType($http->request_headers[$header_name]) == "array") {
for ($header_value = 0; $header_value < count($http->request_headers[$header_name]); $header_value++) {
//log echo $header_name.": ".$http->request_headers[$header_name][$header_value],"\r\n";
}
} else {
//log echo $header_name.": ".$http->request_headers[$header_name],"\r\n";
}
}
//log echo "</PRE>\n";
if ($this->isDebug) {
echo "<H4><LI>HTTP Request body:</LI></H4>error_code:\n" . $http->error_code . "<br/><PRE>request_body:\n" . HtmlEntities($http->request_body) . "</PRE>\n";
}
flush();
$headers = array();
$error = $http->ReadReplyHeaders($headers);
if ($error == "") {
//log echo "<H2><LI>Response headers:</LI</H2>\n<PRE>\n";
for (Reset($headers), $header = 0; $header < count($headers); Next($headers), $header++) {
$header_name = Key($headers);
if (GetType($headers[$header_name]) == "array") {
for ($header_value = 0; $header_value < count($headers[$header_name]); $header_value++) {
if ($this->isDebug) {
echo "http header:" . $header_name . ": " . $headers[$header_name][$header_value], "\r\n";
}
}
} else {
if ($this->isDebug) {
echo $header_name . ": " . $headers[$header_name], "\r\n";
}
}
}
//log echo "</PRE>\n";
flush();
//log echo "<H2><LI>Response body:</LI</H2>\n<PRE>\n";
for (;;) {
//.........这里部分代码省略.........
示例10: SendAPIRequest
function SendAPIRequest($url, $method, $parameters, $oauth, $options, &$response)
{
$this->response_status = 0;
$http = new http_class();
$http->debug = $this->debug && $this->debug_http;
$http->log_debug = true;
$http->sasl_authenticate = 0;
$http->user_agent = $this->oauth_user_agent;
$http->redirection_limit = isset($options['FollowRedirection']) ? intval($options['FollowRedirection']) : 0;
$http->follow_redirect = $http->redirection_limit != 0;
if ($this->debug) {
$this->OutputDebug('Accessing the ' . $options['Resource'] . ' at ' . $url);
}
$post_files = array();
$method = strtoupper($method);
$authorization = '';
$request_content_type = isset($options['RequestContentType']) ? strtolower(trim(strtok($options['RequestContentType'], ';'))) : ($method === 'POST' || isset($oauth) ? 'application/x-www-form-urlencoded' : '');
$files = isset($options['Files']) ? $options['Files'] : array();
if (count($files)) {
foreach ($files as $name => $value) {
if (!isset($parameters[$name])) {
return $this->SetError('it was specified an file parameters named ' . $name);
}
$file = array();
switch (isset($value['Type']) ? $value['Type'] : 'FileName') {
case 'FileName':
$file['FileName'] = $parameters[$name];
break;
case 'Data':
$file['Data'] = $parameters[$name];
break;
default:
return $this->SetError($value['Type'] . ' is not a valid type for file ' . $name);
}
$file['Content-Type'] = isset($value['ContentType']) ? $value['ContentType'] : 'automatic/name';
$post_files[$name] = $file;
}
unset($parameters[$name]);
if ($method !== 'POST') {
$this->OutputDebug('For uploading files the method should be POST not ' . $method);
$method = 'POST';
}
if ($request_content_type !== 'multipart/form-data') {
if (isset($options['RequestContentType'])) {
return $this->SetError('the request content type for uploading files should be multipart/form-data');
}
$request_content_type = 'multipart/form-data';
}
}
if (isset($oauth)) {
if (!$this->Sign($url, $method, $parameters, $oauth, $request_content_type, count($files) !== 0, isset($options['PostValuesInURI']) && $options['PostValuesInURI'], $authorization, $post_values)) {
return false;
}
} else {
$post_values = $parameters;
if (count($parameters)) {
switch ($request_content_type) {
case 'application/x-www-form-urlencoded':
case 'multipart/form-data':
case 'application/json':
break;
default:
$first = strpos($url, '?') === false;
foreach ($parameters as $name => $value) {
if (GetType($value) === 'array') {
foreach ($value as $index => $value) {
$url .= ($first ? '?' : '&') . $name . '=' . UrlEncode($value);
$first = false;
}
} else {
$url .= ($first ? '?' : '&') . $name . '=' . UrlEncode($value);
$first = false;
}
}
}
}
}
if (strlen($authorization) === 0 && !strcasecmp($this->access_token_type, 'Bearer')) {
$authorization = 'Bearer ' . $this->access_token;
}
if (strlen($error = $http->GetRequestArguments($url, $arguments))) {
return $this->SetError('it was not possible to open the ' . $options['Resource'] . ' URL: ' . $error);
}
if (strlen($error = $http->Open($arguments))) {
return $this->SetError('it was not possible to open the ' . $options['Resource'] . ' URL: ' . $error);
}
if (count($post_files)) {
$arguments['PostFiles'] = $post_files;
}
$arguments['RequestMethod'] = $method;
switch ($request_content_type) {
case 'application/x-www-form-urlencoded':
case 'multipart/form-data':
if (isset($options['RequestBody'])) {
return $this->SetError('the request body is defined automatically from the parameters');
}
$arguments['PostValues'] = $post_values;
break;
case 'application/json':
$arguments['Headers']['Content-Type'] = $options['RequestContentType'];
//.........这里部分代码省略.........
示例11: set_time_limit
$password = "";
/* Define your PHP Classes site access name here */
$password_line = __LINE__;
$host_name = "phpclasses.UpperDesign.com";
$uri = "/browse.html/file/5/download/1/name/http.php";
if ($user == "") {
echo "PHP Classes site user was not specified in script " . __FILE__ . " line {$user_line}\n";
exit;
}
if ($password == "") {
echo "PHP Classes site password was not specified in script " . __FILE__ . " line {$password_line}\n";
exit;
}
require "http.php";
set_time_limit(0);
$http_connection = new http_class();
$error = $http_connection->Open(array("HostName" => $host_name));
if ($error == "") {
$error = $http_connection->SendRequest(array("RequestURI" => $uri, "RequestMethod" => "POST", "PostValues" => array("alias" => $user, "password" => $password, "Submit" => "Login", "dologin" => 1)));
if ($error == "") {
$error = $http_connection->ReadReplyHeaders(&$headers);
if ($error == "") {
for ($header = 0, Reset($headers); $header < count($headers); Next($headers), $header++) {
if (Key($headers) == "set-cookie") {
break;
}
}
if ($header < count($headers)) {
for (;;) {
$error = $http_connection->ReadReplyBody(&$body, 1000);
if ($error != "" || strlen($body) == 0) {
示例12: set_time_limit
* @(#) $Header: /opt2/ena/metal/http/test_http_post.php,v 1.5 2004/08/11 00:46:11 mlemos Exp $
*
*/
?>
<HTML>
<HEAD>
<TITLE>Test for Manuel Lemos' PHP HTTP class to simulate a HTTP POST form submission</TITLE>
</HEAD>
<BODY>
<H1><CENTER>Test for Manuel Lemos' PHP HTTP class to simulate a HTTP POST form submission</CENTER></H1>
<HR>
<UL>
<?php
require "http.php";
set_time_limit(0);
$http = new http_class();
$http->timeout = 0;
$http->data_timeout = 0;
$http->debug = 0;
$http->html_debug = 1;
$url = "http://www.cs.tut.fi/cgi-bin/run/~jkorpela/echoraw.cgi";
$error = $http->GetRequestArguments($url, $arguments);
$arguments["RequestMethod"] = "POST";
$arguments["PostValues"] = array("somefield" => "Upload forms", "MAX_FILE_SIZE" => "1000000");
$arguments["PostFiles"] = array("userfile" => array("Data" => "This is just a plain text attachment file named attachment.txt .", "Name" => "attachment.txt", "Content-Type" => "automatic/name"), "anotherfile" => array("FileName" => "test_http_post.php", "Content-Type" => "automatic/name"));
$arguments["Referer"] = "http://www.alltheweb.com/";
echo "<H2><LI>Opening connection to:</H2>\n<PRE>", HtmlEntities($arguments["HostName"]), "</PRE>\n";
flush();
$error = $http->Open($arguments);
if ($error == "") {
$error = $http->SendRequest($arguments);
示例13: _saveUserPhoto
protected function _saveUserPhoto($from, $to)
{
$ret = 0;
$img = '';
$arguments = array();
$http = new http_class();
$http->user_agent = 'glFusion/' . GVERSION;
$error = $http->GetRequestArguments($from, $arguments);
$error = $http->Open($arguments);
if ($error == "") {
$error = $http->SendRequest($arguments);
if ($error == "") {
for (;;) {
$error = $http->ReadReplyBody($body, 10240);
if ($error != "" || strlen($body) == 0) {
break;
}
$img = $img . $body;
}
$ret = file_put_contents($to, $img);
}
}
$http->Close();
return $ret;
}
示例14: UpdateStep4
function UpdateStep4()
{
global $clang, $scriptname, $homedir, $buildnumber, $updatebuild, $debug, $rootdir, $publicdir, $tempdir, $database_exists, $databasetype, $action, $demoModeOnly;
echo '<div class="header ui-widget-header">'.sprintf($clang->gT('ComfortUpdate step %s'),'4').'</div><div class="updater-background"><br />';
if (!isset( $_SESSION['updateinfo']))
{
echo $clang->gT('On requesting the update information from limesurvey.org there has been an error:').'<br />';
if ($updateinfo['error']==1)
{
setGlobalSetting('updatekey','');
echo $clang->gT('Your update key is invalid and was removed. ').'<br />';
}
else
echo $clang->gT('On requesting the update information from limesurvey.org there has been an error:').'<br />';
}
else
{
$updateinfo=$_SESSION['updateinfo'];
}
// this is the last step - Download the zip file, unpack it and replace files accordingly
// Create DB and file backups now
require_once("classes/pclzip/pclzip.lib.php");
// require_once('classes/pclzip/pcltrace.lib.php');
// require_once('classes/pclzip/pclzip-trace.lib.php');
// PclTraceOn(2);
require_once($homedir."/classes/http/http.php");
$downloaderror=false;
$http=new http_class;
// Allow redirects
$http->follow_redirect=1;
/* Connection timeout */
$http->timeout=0;
/* Data transfer timeout */
$http->data_timeout=0;
$http->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
$http->GetRequestArguments("http://update.limesurvey.org/updates/download/{$updateinfo['downloadid']}",$arguments);
$http->RestoreCookies($_SESSION['updatesession']);
$error=$http->Open($arguments);
$error=$http->SendRequest($arguments);
$http->ReadReplyHeaders($headers);
if ($headers['content-type']=='text/html')
{
@unlink($tempdir.'/update.zip');
}
elseif($error=='') {
$body='';
$pFile = fopen($tempdir.'/update.zip', 'w');
for(;;){
$error = $http->ReadReplyBody($body,100000);
if($error != "" || strlen($body)==0) break;
fwrite($pFile, $body);
}
fclose($pFile);
}
else
{
print( $error );
}
// Now remove all files that are to be deleted according to update process
foreach ($updateinfo['files'] as $afile)
{
if ($afile['type']=='D' && file_exists($rootdir.$afile['file']))
{
if (is_file($rootdir.$afile['file']))
{
unlink($rootdir.$afile['file']);
}
else{
rmdirr($rootdir.$afile['file']);
}
echo sprintf($clang->gT('File deleted: %s'),$afile['file']).'<br />';
}
}
//Now unzip the new files over the existing ones.
if (file_exists($tempdir.'/update.zip')){
$archive = new PclZip($tempdir.'/update.zip');
if ($archive->extract(PCLZIP_OPT_PATH, $rootdir.'/', PCLZIP_OPT_REPLACE_NEWER)== 0) {
die("Error : ".$archive->errorInfo(true));
}
else
{
echo $clang->gT('New files were successfully installed.').'<br />';
unlink($tempdir.'/update.zip');
}
}
else
{
echo $clang->gT('There was a problem downloading the update file. Please try to restart the update process.').'<br />';
$downloaderror=true;
}
// PclTraceDisplay();
//.........这里部分代码省略.........
示例15: get
/**
* Fetch a remote URI then return results.
*
* If this method is triggered without the second parameter, <b>$target</b>, then
* result will be return in the following format:
*
* <pre>array(
* 'header' => array(
* 'header_1' => 'header_value_1',
* 'header_2' => 'header_value_2',
* etc...
* ),
* 'body' => 'fetched response body'
* )</pre>
*
* Otherwise, the fetched response body will be saved to the local file specified
* by the variable <b>$target</b>. The example below will download the remote image
* <b>http://placehold.it/300x200.gif</b> then save to the local file
* <b>/tmp/downloaded_image.gif</b>:
*
* <pre>JSNUtilsHttp::get(
* 'http://placehold.it/300x200.gif',
* '/tmp/downloaded_image.gif'
* );</pre>
*
* When the second parameter is set in method call, the method will always return
* the boolean value <b>true</b> if file is successfully saved or <b>false</b>
* if file is not saved.
*
* @param string $uri Remote URI for fetching content.
* @param string $target Set to a file path to save fetched content as local file.
* @param boolean $validateHeader Check for 200 OK header or not?
* @param array $options Custom options to pass to http_class object.
*
* @return array array('header' => 'Associative array of fetched header', 'body' => 'Fetched content')
*/
public static function get($uri, $target = '', $validateHeader = true, $options = array())
{
// Preset return result
$result = array();
// Initialize HTTP client
$http = new http_class();
$http->follow_redirect = 1;
$http->redirection_limit = 5;
$http->GetRequestArguments($uri, $arguments);
// Set custom options
if (is_array($options) and count($options)) {
foreach ($options as $k => $v) {
$arguments[$k] = $v;
}
}
// Open connection
if (($error = $http->Open($arguments)) == '') {
if (($error = $http->SendRequest($arguments)) == '') {
// Get response header
$header = array();
if (($error = $http->ReadReplyHeaders($header)) != '') {
throw new Exception(JText::sprintf('JSN_TPLFW_HTTP_CONNECTION_ERROR', $error));
}
$result['header'] = $header;
// Validate header
if ($validateHeader) {
foreach ($result['header'] as $header => $value) {
if (strtolower(substr($header, 0, 5)) == 'http/' and strpos($header, '200') === false) {
throw new Exception(JText::sprintf('JSN_TPLFW_HTTP_CONNECTION_ERROR', substr($header, strpos($header, ' '))));
}
}
}
// Get response body
$result['body'] = '';
while (true) {
if (($error = $http->ReadReplyBody($body, 1000)) != '' or strlen($body) == 0) {
break;
}
$result['body'] .= $body;
}
// Validate header
if (is_array($validateHeader)) {
foreach ($validateHeader as $k => $v) {
foreach ($result['header'] as $header => $value) {
if (strcasecmp($header, $k) == 0) {
is_array($v) or $v = array($v);
if (!in_array($value, $v)) {
throw new Exception($result['body']);
}
}
}
}
}
} else {
throw new Exception(JText::sprintf('JSN_TPLFW_HTTP_CONNECTION_ERROR', $error));
}
// Close connection
$http->Close();
} else {
throw new Exception(JText::sprintf('JSN_TPLFW_HTTP_CONNECTION_ERROR', $error));
}
// Write to local file if target is given
empty($target) or JFile::write($target, $result['body']);
return $result;
//.........这里部分代码省略.........