⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 http.php

📁 网络硬盘_支持1GB文件上传和续传_无错版
💻 PHP
📖 第 1 页 / 共 4 页
字号:
				$boundary="--".md5(uniqid(time()));				$this->request_headers["Content-Type"]="multipart/form-data; boundary=".$boundary;				$post_parts=array();				$files=(IsSet($arguments["PostFiles"]) ? $arguments["PostFiles"] : array());				Reset($files);				$end=(GetType($input=Key($files))!="string");				for(;!$end;)				{					if(strlen($error=$this->GetFileDefinition($files[$input],$definition)))						return("3 ".$error);					$headers="--".$boundary."\r\nContent-Disposition: form-data; name=\"".$input."\"; filename=\"".$definition["NAME"]."\"\r\nContent-Type: ".$definition["Content-Type"]."\r\n\r\n";					$part=count($post_parts);					$post_parts[$part]=array("HEADERS"=>$headers);					if(IsSet($definition["FILENAME"]))					{						$post_parts[$part]["FILENAME"]=$definition["FILENAME"];						$data="";					}					else						$data=$definition["DATA"];					$post_parts[$part]["DATA"]=$data;					$body_length+=strlen($headers)+$definition["Content-Length"]+strlen("\r\n");					Next($files);					$end=(GetType($input=Key($files))!="string");				}				if(IsSet($arguments["PostValues"]))				{					$values=$arguments["PostValues"];					if(GetType($values)!="array")						return($this->SetError("5 it was not specified a valid POST method values array"));					for(Reset($values),$value=0;$value<count($values);Next($values),$value++)					{						$input=Key($values);						$headers="--".$boundary."\r\nContent-Disposition: form-data; name=\"".$input."\"\r\n\r\n";						$data=$values[$input];						$post_parts[]=array("HEADERS"=>$headers,"DATA"=>$data);						$body_length+=strlen($headers)+strlen($data)+strlen("\r\n");					}				}				$body_length+=strlen("--".$boundary."--\r\n");			}			elseif(IsSet($arguments["PostValues"]))			{				$values=$arguments["PostValues"];				if(GetType($values)!="array")					return($this->SetError("5 it was not specified a valid POST method values array"));				for($this->request_body="",Reset($values),$value=0;$value<count($values);Next($values),$value++)				{                    /*                    Fixed the array-like value in $arguments["PostValues"]                    This is because PHP parse txt[key1]=val1&txt[key2]=$val2 into array,                    so when we post data to host,we need to reverse this process                    */                    if(is_array($values[Key($values)]))                    {                        foreach($values[Key($values)] as $k => $v)                        $this->request_body.=Key($values).UrlEncode("[$k]")."=".UrlEncode($v).'&';                    }                    else					$this->request_body.=Key($values)."=".UrlEncode($values[Key($values)]).'&';				}                $this->request_body=substr($this->request_body,0,-1);				$this->request_headers["Content-Type"]="application/x-www-form-urlencoded";			}			else			{				if(IsSet($arguments["Body"]))					$this->request_body=$arguments["Body"];			}		}		else		{			if(IsSet($arguments["Body"]))				$this->request_body=$arguments["Body"];		}		if(IsSet($arguments["ProxyUser"]))			$this->proxy_request_user=$arguments["ProxyUser"];		elseif(IsSet($this->proxy_user))			$this->proxy_request_user=$this->proxy_user;		if(IsSet($arguments["ProxyPassword"]))			$this->proxy_request_password=$arguments["ProxyPassword"];		elseif(IsSet($this->proxy_password))			$this->proxy_request_password=$this->proxy_password;		if(IsSet($arguments["ProxyRealm"]))			$this->proxy_request_realm=$arguments["ProxyRealm"];		elseif(IsSet($this->proxy_realm))			$this->proxy_request_realm=$this->proxy_realm;		if(IsSet($arguments["ProxyWorkstation"]))			$this->proxy_request_workstation=$arguments["ProxyWorkstation"];		elseif(IsSet($this->proxy_workstation))			$this->proxy_request_workstation=$this->proxy_workstation;		if(IsSet($arguments["AuthUser"]))			$this->request_user=$arguments["AuthUser"];		elseif(IsSet($this->user))			$this->request_user=$this->user;		if(IsSet($arguments["AuthPassword"]))			$this->request_password=$arguments["AuthPassword"];		elseif(IsSet($this->password))			$this->request_password=$this->password;		if(IsSet($arguments["AuthRealm"]))			$this->request_realm=$arguments["AuthRealm"];		elseif(IsSet($this->realm))			$this->request_realm=$this->realm;		if(IsSet($arguments["AuthWorkstation"]))			$this->request_workstation=$arguments["AuthWorkstation"];		elseif(IsSet($this->workstation))			$this->request_workstation=$this->workstation;        if(IsSet($this->request_user))		{			$this->request_headers["Authorization"]="Basic ".base64_encode($this->request_user.":".$this->request_password);		}		if(strlen($this->proxy_host_name)==0)			$request_uri=$this->request_uri;		else		{			switch(strtolower($this->protocol))			{				case "http":					$default_port=80;					break;				case "https":					$default_port=443;					break;			}			$request_uri=strtolower($this->protocol)."://".$this->host_name.(($this->host_port==0 || $this->host_port==$default_port) ? "" : ":".$this->host_port).$this->request_uri;		}		if($this->use_curl)		{			$version=(GetType($v=curl_version())=="array" ? (IsSet($v["version"]) ? $v["version"] : "0.0.0") : (ereg("^libcurl/([0-9]+\\.[0-9]+\\.[0-9]+)",$v,$m) ? $m[1] : "0.0.0"));			$curl_version=100000*intval($this->Tokenize($version,"."))+1000*intval($this->Tokenize("."))+intval($this->Tokenize(""));			$protocol_version=($curl_version<713002 ? "1.0" : $this->protocol_version);		}		else			$protocol_version=$this->protocol_version;		$this->request=$this->request_method." ".$request_uri." HTTP/".$protocol_version;		if($body_length		|| ($body_length=strlen($this->request_body)))			$this->request_headers["Content-Length"]=$body_length;		for($headers=array(),$host_set=0,Reset($this->request_headers),$header=0;$header<count($this->request_headers);Next($this->request_headers),$header++)		{			$header_name=Key($this->request_headers);			$header_value=$this->request_headers[$header_name];			if(GetType($header_value)=="array")			{				for(Reset($header_value),$value=0;$value<count($header_value);Next($header_value),$value++)					$headers[]=$header_name.": ".$header_value[Key($header_value)];			}			else				$headers[]=$header_name.": ".$header_value;			if(strtolower(Key($this->request_headers))=="host")			{				$this->request_host=strtolower($header_value);				$host_set=1;			}		}		if(!$host_set)		{			$headers[]="Host: ".$this->host_name;			$this->request_host=strtolower($this->host_name);		}        //get cookie from session,and send the website cookie        if(count($_SESSION['cookies'])&&$this->support_cookies)//if(count($this->cookies))		{            $this->cookies= $_SESSION['cookies'];			$cookies=array();			$this->PickCookies($cookies,0);			if(strtolower($this->protocol)=="https")				$this->PickCookies($cookies,1);			if(count($cookies))			{				$h=count($headers);				$headers[$h]="Cookie:";				for(Reset($cookies),$cookie=0;$cookie<count($cookies);Next($cookies),$cookie++)				{					$cookie_name=Key($cookies);					$headers[$h].=" ".UrlEncode($cookie_name)."=".$cookies[$cookie_name]["value"].";";				}			}		}		if($this->use_curl)		{			if($body_length			&& strlen($this->request_body)==0)			{				for($request_body="",$success=1,$part=0;$part<count($post_parts);$part++)				{					$request_body.=$post_parts[$part]["HEADERS"].$post_parts[$part]["DATA"];					if(IsSet($post_parts[$part]["FILENAME"]))					{						if(!($file=@fopen($post_parts[$part]["FILENAME"],"rb")))						{							$this->SetPHPError("could not open upload file ".$post_parts[$part]["FILENAME"], $php_errormsg);							$success=0;							break;						}						while(!feof($file))						{							if(GetType($block=@fread($file,$this->file_buffer_length))!="string")							{								$this->SetPHPError("could not read upload file", $php_errormsg);								$success=0;								break;							}							$request_body.=$block;						}						fclose($file);						if(!$success)							break;					}					$request_body.="\r\n";				}				$request_body.="--".$boundary."--\r\n";			}			else				$request_body=$this->request_body;			curl_setopt($this->connection,CURLOPT_HEADER,1);			curl_setopt($this->connection,CURLOPT_RETURNTRANSFER,1);			if($this->timeout)				curl_setopt($this->connection,CURLOPT_TIMEOUT,$this->timeout);			curl_setopt($this->connection,CURLOPT_SSL_VERIFYPEER,0);			curl_setopt($this->connection,CURLOPT_SSL_VERIFYHOST,0);			$request=$this->request."\r\n".implode("\r\n",$headers)."\r\n\r\n".$request_body;			curl_setopt($this->connection,CURLOPT_CUSTOMREQUEST,$request);			if($this->debug)				$this->OutputDebug("C ".$request);			if(!($success=(strlen($this->response=curl_exec($this->connection))!=0)))			{				$error=curl_error($this->connection);				$this->SetError("Could not execute the request".(strlen($error) ? ": ".$error : ""));			}		}		else		{			if(($success=$this->PutLine($this->request)))			{				for($header=0;$header<count($headers);$header++)				{					if(!$success=$this->PutLine($headers[$header]))						break;				}				if($success				&& ($success=$this->PutLine(""))				&& $body_length)				{					if(strlen($this->request_body))						$success=$this->PutData($this->request_body);					else					{						for($part=0;$part<count($post_parts);$part++)						{							if(!($success=$this->PutData($post_parts[$part]["HEADERS"]))							|| !($success=$this->PutData($post_parts[$part]["DATA"])))								break;							if(IsSet($post_parts[$part]["FILENAME"]))							{								if(!($file=@fopen($post_parts[$part]["FILENAME"],"rb")))								{									$this->SetPHPError("could not open upload file ".$post_parts[$part]["FILENAME"], $php_errormsg);									$success=0;									break;								}								while(!feof($file))								{									if(GetType($block=@fread($file,$this->file_buffer_length))!="string")									{										$this->SetPHPError("could not read upload file", $php_errormsg);										$success=0;										break;									}									if(!($success=$this->PutData($block)))										break;								}								fclose($file);								if(!$success)									break;							}							if(!($success=$this->PutLine("")))								break;						}						if(!($success=$this->PutLine("--".$boundary."--")))							break;					}					if($success)						$sucess=$this->FlushData();				}			}		}		if(!$success)			return($this->SetError("5 could not send the HTTP request: ".$this->error));		$this->state="RequestSent";		return("");	}	Function SetCookie($name, $value, $expires="" , $path="/" , $domain="" , $secure=0)	{		if(strlen($this->error))			return($this->error);		if(strlen($name)==0)			return($this->SetError("it was not specified a valid cookie name"));		if(strlen($path)==0		|| strcmp($path[0],"/"))			return($this->SetError($path." is not a valid path for setting cookie ".$name));		if($domain==""		|| !strpos($domain,".",$domain[0]=="." ? 1 : 0))			return($this->SetError($domain." is not a valid domain for setting cookie ".$name));		$domain=strtolower($domain);		$this->cookies[$secure][$domain][$path][$name]=array(			"name"=>$name,			"value"=>$value,			"domain"=>$domain,			"path"=>$path,			"expires"=>$expires,			"secure"=>$secure		);		return("");	}	Function ReadReplyHeadersResponse(&$headers)	{		$headers=array();		if(strlen($this->error))			return($this->error);		switch($this->state)		{			case "Disconnected":				return($this->SetError("1 connection was not yet established"));			case "Connected":				return($this->SetError("2 request was not sent"));			case "RequestSent":				break;			default:				return($this->SetError("3 can not get request headers in the current connection state"));		}		$this->content_length=$this->read_length=$this->read_response=$this->remaining_chunk=0;		$this->content_length_set=$this->chunked=$this->last_chunk_read=$chunked=0;		for($this->response_status="";;)		{			$line=$this->GetLine();			if(GetType($line)!="string")				return($this->SetError("4 could not read request reply: ".$this->error));			if(strlen($this->response_status)==0)			{				if(!eregi($match="^http/[0-9]+\\.[0-9]+[ \t]+([0-9]+)[ \t]*(.*)\$",$line,$matches))					return($this->SetError("3 it was received an unexpected HTTP response status"));				$this->response_status=$matches[1];				$this->response_message=$matches[2];			}			if($line=="")			{				if(strlen($this->response_status)==0)					return($this->SetError("3 it was not received HTTP response status"));				$this->state="GotReplyHeaders";				break;			}			$header_name=strtolower($this->Tokenize($line,":"));			$header_value=Trim(Chop($this->Tokenize("\r\n")));			if(IsSet($headers[$header_name]))			{				if(GetType($headers[$header_name])=="string")					$headers[$header_name]=array($headers[$header_name]);				$headers[$header_name][]=$header_value;			}			else				$headers[$header_name]=$header_value;			switch($header_name)			{				case "content-length":					$this->content_length=intval($headers[$header_name]);					$this->content_length_set=1;					break;				case "transfer-encoding":					$encoding=$this->Tokenize($header_value,"; \t");					if(!$this->use_curl					&& !strcmp($encoding,"chunked"))						$chunked=1;					break;				case "set-cookie":					if($this->support_cookies)					{						if(GetType($headers[$header_name])=="array")							$cookie_headers=$headers[$header_name];						else							$cookie_headers=array($headers[$header_name]);						for($cookie=0;$cookie<count($cookie_headers);$cookie++)						{							$cookie_name=trim(UrlDecode($this->Tokenize($cookie_headers[$cookie],"=")));							$cookie_value=UrlDecode($this->Tokenize(";"));							$domain=$this->request_host;							$path="/";							$expires="";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -