<?php
/**
* HTTP类
* Version:0.2 alpha
* Email:o0lazy0o at gmail dot com
* QQ:ODgyMDg1Nw
* Homepage:none
* Copyright:none,freely to use.
*/
class http{
var $CURL;
var $Socket;
var $Request;
var $AutoLocation=true;
var $CRLF="\r\n";
var $Header=array(
'Accept'=>"*/*",
'Accept-Language'=>"zh-cn,zh",
'Accept-Encoding'=>"gzip, deflate",
'User-Agent'=>"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2)",
'Pragma'=>"no-cache",
'Cache-Control'=>"no-cache",
'Host'=>"",
'Referer'=>"",
'Cookie'=>""
);
var $Hostname;
var $Server;
var $Port=80;
var $SSL;
var $Timeout=10;
var $Document='/';
var $CookieFile;
var $ProxyHost;
var $ProxyPort=8080;
//var $ProxyUser;验证代理不支持
//var $ProxyPass;验证代理不支持
var $Debug=false;
var $ErrNo;
var $ErrStr;
var $Status;
var $TransferEncoding;
var $ContentEncoding;
var $CheckReferer;
var $CheckCookie;
var $SpeedLimit;
var $Time;
/**
* 构造函数
* 变量初始化
*/
function http($URL,$Debug=false){
$this->Debug=&$Debug;
$Parser=parse_url($URL);
$this->SSL=strtoupper($Parser['scheme'])=="HTTPS"?true:false;
$this->Hostname=$Parser['host'];
$this->Header['Host']=$this->Hostname;
$this->Server=gethostbyname($this->Hostname);
$this->Port=empty($Parser['port'])?$this->SSL?443:80:$Parser['port'];
empty($Parser['path'])?null:$this->Document=empty($Parser['query'])?$Parser['path']:"{$Parser['path']}?{$Parser['query']}";
if(function_exists('curl_init')&&function_exists('curl_setopt')&&function_exists('curl_exec')){
$this->CURL=true;
}
}
/**
* 连接函数
* 连接服务器/代理
* 如果可以使用CURL就优先使用CURL否则就用fsocket发送HTTP请求
* 如果fsocket都给禁了...
* !@#$$#%$%^%$&%^
*/
function connect(){
if($this->CURL===true){
$this->Socket=curl_init();
}else{
if(!empty($this->ProxyHost) && !empty($this->ProxyPort)){
$this->Socket=$this->Socket=fsockopen($this->ProxyHost,$this->ProxyPort,$this->ErrNo,$this->ErrStr,$this->Timeout);
}else{
$this->Socket=$this->SSL?fsockopen('ssl://'.$this->Server,$this->Port,$this->ErrNo,$this->ErrStr,$this->Timeout):fsockopen($this->Server,$this->Port,$this->ErrNo,$this->ErrStr,$this->Timeout);
}
}
if(!$this->Socket){
if($this->CURL===true){
$this->ErrNo=curl_errno($this->Socket);
$this->ErrStr=curl_error($this->Socket);
}
exit("{$this->ErrNo}=>{$this->ErrStr}");
}
}
/**
* HTTP头请求
* 默认HTTP头生成
* 如果没有定义类型就按$Header里的生成,数组里为空的跳过
* 如果给出$Name就添加到Request
*/
function make_head($Name=null,$Value=null){
if(empty($Name)&&empty($Value)){
$Connection="Close";
strtoupper($Name)=='CONNECTION'?$Connection=$Value:null;
foreach($this->Header as $Key=>$Var){
empty($Var)?null:$this->Request.="$Key: $Var{$this->CRLF}";
}
$this->Request.="Connection: $Connection";
}else{
$this->Request.="$Name: $Value{$this->CRLF}";
}
return $this->Request;
}
/**
* HTTP头解码
* 从http头里解析出服务器的状态,Cookies,编码等
*/
function decode_head($URL,$Header){
if($this->Debug){
var_dump($Header);
}
$this->Status=$this->parse_status($Header);
$this->AutoLocation?$this->parse_redirect($Header):null;
$this->parse_cookie($Header);
$this->parse_encoding($Header);
}
/**
* 解析服务器返回的状态
*/
function parse_status(&$Header){
$Regexp="/HTTP\/1\.[01] ([0-9]+) [a-z]+/i";
preg_match($Regexp,$Header,$Tmp);
return $Tmp[1];
}
/**
* 解析重定向
* 注意非HTML的<meta>跟JS的
*/
function parse_redirect(&$Header){
$Regexp="/location:([^\n]+)\n/i";
preg_match($Regexp,$Header,$Tmp);
return trim($Tmp[1]);
}
/**
* 解析Cookie并保存备用
*/
function parse_cookie($Header){
$Regexp="/Set-Cookie:((?:[^=]+)=(?:[^\n;]+)).*/i";
preg_match_all($Regexp,$Header,$Tmp);
foreach($Tmp[1] as $Var){
$Var=trim($Var);
$this->Header['Cookie'].="$Var;";
}
return $this->Header['Cookie'];
}
/**
* 解析HTTP头的传输编码跟压缩方法
*/
function parse_encoding($Header){
$Regexp="/Transfer-Encoding:([^\n]+)\n/i";
preg_match($Regexp,$Header,$Tmp);
$this->TransferEncoding=strtoupper(trim($Tmp[1]));
$Regexp="/Content-Encoding:([^\n]+)\n/i";
preg_match($Regexp,$Header,$Tmp);
$this->ContentEncoding=strtoupper(trim($Tmp[1]));
return true;
}
/**
* 解析经过编码或者压缩过的内容
* 支持:chunked,gzip,deflate
* 备注:
* 只根据服务器返回的Transfer-Encoding,Content-Encoding进行处理而非根据判断文件头进行处理的.
* 所以在某些网站可能会出现"乱码"
*/
function decode_body($String,$EOL="\r\n"){
if(strtoupper($this->TransferEncoding)=='CHUNKED'){
$Return=null;
$EndLength=strlen($EOL);
do{
$String=ltrim($String);
$StartPos=strpos($String,$EOL);
$Length=hexdec(substr($String,0,$StartPos));
if($this->ContentEncoding=='DEFLATE'){
$Return.=gzinflate(substr($String,($StartPos+$EndLength+10),$Length));
}elseif($this->ContentEncoding=='GZIP'){
$Return.=gzuncompress(substr($String,($StartPos+$EndLength),$Length));
}else{
$Return.=substr($String,($StartPos+$EndLength),$Length);
}
$String=substr($String,($Length+$StartPos+$EndLength));
$End=trim($String);
}while(!empty($End));
return $Return;
}elseif($this->ContentEncoding=='GZIP' && !$this->CURL){
return gzuncompress($String);
}elseif($this->ContentEncoding=='DEFLATE' && !$this->CURL){
return gzinflate(substr($String,10));
}else{
return $String;
}
}
/**
* 发送并读取服务器返回值并分离出HTTP头跟内容
* 用于Socket建立连接
*/
function request(){
fwrite($this->Socket,$this->Request,strlen($this->Request));
while(!feof($this->Socket)){
$Response.=fgets($this->Socket,256);
}
$Response=explode($this->CRLF.$this->CRLF,$Response);
$Header=array_shift($Response);
$this->decode_head(null,$Header);
$Response=trim(implode($this->CRLF.$this->CRLF,$Response));
return $Response;
}
/**
* 发送HTTP头并读取数据
*/
function exec(){
if($this->CURL===true){
$Return=curl_exec($this->Socket);
if($this->Debug){
var_dump(curl_error($this->Socket));
var_dump(curl_errno($this->Socket));
}
}else{
$Return=$this->request();
}
if($this->Debug){
var_dump($this->Request);
var_dump($Return);
}
return $this->decode_body($Return);
}
/**
* 设置HTTP 的方法
* 只支持HEAD,GET,POST
*/
function set_header($Method='get',$Document,$Data=null){
$AllowMethod=array('HEAD','GET','POST');
if(!in_array(strtoupper($Method),$AllowMethod)){
return false;
}
empty($Document)?null:$this->Document=$Document;
if($this->CURL){
$this->set_curl_head($Method,$Data);
}else{
$this->set_socket_head($Method,$Data);
}
}
/**
* 在可用CURL的情况下设置,HTTP头
*/
function set_curl_head($Method,$Data){
empty($this->CookieFile)?$this->CookieFile=tempnam('./',md5($this->Hostname)):null;
curl_setopt($this->Socket,CURLOPT_RETURNTRANSFER,true);
if(!empty($this->ProxyHost)&&!empty($this->ProxyPort)){
curl_setopt($this->Socket,CURLOPT_PROXY,"{$this->ProxyHost}:{$this->ProxyPort}");
}
if($Method=='HEAD'){
curl_setopt($this->Socket,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($this->Socket,CURLOPT_HEADER,true);
curl_setopt($this->Socket,CURLOPT_HEADERFUNCTION,array(&$this,'decode_head'));
curl_setopt($this->Socket,CURLOPT_CUSTOMREQUEST,"HEAD");
}elseif($Method=='POST'){
curl_setopt($this->Socket,CURLOPT_POST,true);
curl_setopt($this->Socket,CURLOPT_POSTFIELDS,$Data);
}elseif($Method=='GET'){
//curl_setopt($this->Socket,CURLOPT_COOKIEJAR,$this->CookieFile);
//curl_setopt($this->Socket,CURLOPT_COOKIEFILE,$this->CookieFile);
}
if($this->SSL){
curl_setopt($this->Socket,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($this->Socket,CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($this->Socket,CURLOPT_URL,'https://'.$this->Hostname.$this->Document);
}else{
curl_setopt($this->Socket,CURLOPT_URL,'http://'.$this->Hostname.$this->Document);
}
curl_setopt($this->Socket,CURLOPT_COOKIEJAR,$this->CookieFile);
curl_setopt($this->Socket,CURLOPT_COOKIEFILE,$this->CookieFile);
curl_setopt($this->Socket,CURLOPT_REFERER,$this->Header['Referer']);
curl_setopt($this->Socket,CURLOPT_USERAGENT,$this->Header['User-Agent']);
}
/**
* 在Socket的情况下设置,HTTP头
*/
function set_socket_head($Method){
if(!empty($this->ProxyHost)&&!empty($this->ProxyPort)){
$this->Request="{$Method} http://{$this->Hostname}{$this->Document} HTTP/1.1{$this->CRLF}";
}else{
$this->Request="{$Method} {$this->Document} HTTP/1.1{$this->CRLF}";
}
$this->make_head();
}
/**
* 发送HEAD请求
* 暂不支持基于代理的HTTPS HEAD
* 原因是自己不知道要怎么处理
*/
function head($Document=null){
$this->connect();
$this->set_header('HEAD',$Document);
if(!$this->CURL){
$this->Request.=$this->CRLF.$this->CRLF;
}
$this->exec();
if($this->Status==200){
return true;
}else{
return false;
}
}
/**
* 发送GET请求,自动保存cookie,设置referer,暂不支持自动重定向,处理服务器编码跟解压==
*/
function get($Document=null){
$this->connect();
$this->Header['Referer']="http://{$this->Hostname}{$this->Document}";
$this->set_header('GET',$Document);
if(!$this->CURL){
$this->Request.=$this->CRLF.$this->CRLF;
}
return $this->exec();
}
/**
* 发送POST请求,自动保存cookie,设置referer,暂不支持发送文件,自动重定向,处理服务器编码跟解压==
*/
function post($Document,$Data=null){
if(!is_array($Data)){
return false;
}
foreach($Data as $Key=>$Var){
$Tmp[]="$Key=".urlencode($Var);
}
$Data=implode('&',$Tmp);
$this->connect();
$this->Header['Referer']="http://{$this->Hostname}{$this->Document}";
$this->Header['Content-Type']='application/x-www-form-urlencoded';
$this->Header['Content-Length']=strlen($Data);
$this->set_header('POST',$Document,$Data);
if(!$this->CURL){
$this->Request.=$this->CRLF.$this->CRLF;
$this->Request.=$Data;
}
return $this->exec();
}
/**
* 关闭连接
*/
function close($Handle=null){
if($this->CURL){
curl_close($this->Socket);
unlink($this->CookieFile);//不要忘记删除文件
}else{
fclose($this->Socket);
}
return true;
}
function send_file($Source,$Destination,$AllowPartial=true){
//#获取文件状态
$FileStatus=stat($Source);
$LastModTime=$FileStatus['mtime'];
$FileHash=md5($FileStatus['mtime'].'='.$FileStatus['ino'].'='.$FileStatus['size']);
$Etag='"'.$FileHash.'-'.crc32($FileHash).'"';
#//获取文件状态
header('Last-Modified: '.gmdate("D, d M Y H:i:s",$LastModTime).' GMT');
header("ETag: $Etag");
//#浏览器缓存检测处理
if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $LastModTime){
return header("HTTP/1.1 304 Not Modified");
}
if(isset($_SERVER['HTTP_IF_UNMODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_UNMODIFIED_SINCE']) < $lastModified){
return header("HTTP/1.1 304 Not Modified");
}
if(isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag){
return header("HTTP/1.1 304 Not Modified");
}
#//浏览器缓存检测处理*/
empty($Destination)?$Destination=basename($Source):null;
$ContentType=$this->mime_type($Source);
$FileSize=$FileStatus['size'];
$ContentLength=$FileSize;
if($AllowPartial==false){
header('Pragma: cache');
header('Cache-Control: public, must-revalidate, max-age=0');
header('Content-Transfer-Encoding: binary');
header('Content-Encoding: none');
header('Content-type: ' . $ContentType);
header('Content-Disposition: attachment; filename="' .rawurlencode(basename($Destination)).'"');
header("Content-length: $ContentLength");
echo readfile($Source);
exit();
}
$IsPartial=false;
if(isset($_SERVER['HTTP_RANGE'])){
if(preg_match('/^bytes=(\d*)-(\d*)$/',$_SERVER['HTTP_RANGE'],$Matches)){
$StartPos=$Matches[1];
$EndPos=$Matches[2];
if($StartPos=='' && $EndPos=''){
return header('HTTP/1.1 400 Bad Request');
}
if($StartPos == ''){
$StartPos = $FileSize - $EndPos;
$EndPos = $FileSize - 1;
}elseif($EndPos == ''){
$EndPos = $FileSize - 1;
}
$StartPos = $StartPos < 0 ? 0 : $StartPos;
$EndPos = $EndPos > $FileSize - 1 ? $FileSize - 1 : $EndPos;
$Length = $EndPos-$StartPos + 1;
if ($Length < 0){
return header('HTTP/1.1 400 Bad Request');
}
$ContentLength = $Length;
$IsPartial = true;
}
}
if($IsPartial){
header('HTTP/1.1 206 Partial Content');
header("Content-Range: bytes $StartPos-$EndPos/$FileSize");
}else{
header("HTTP/1.1 200 OK");
$StartPos = 0;
$EndPos = $ContentLength - 1;
}
header('Pragma: cache');
header('Cache-Control: public, must-revalidate, max-age=0');
header('Accept-Ranges: bytes');
header('Content-type: '.$ContentType);
header('Content-Length: '.$ContentLength);
header('Content-Disposition: attachment; filename="'.rawurlencode($Destination).'"');
header("Content-Transfer-Encoding: binary");
header('Content-Encoding: none');
$BufferSize=2048;
$BytesSent=0;
$Handle=fopen($Source,'rb');
fseek($Handle,$StartPos);
while($BytesSent < $ContentLength && !feof($Handle) && connection_status() == 0){
$ReadBuffer=$ContentLength-$BytesSent<$BufferSize?$ContentLength-$BytesSent:$BufferSize;
$Buffer=fread($Handle,$ReadBuffer);
echo $Buffer;
ob_flush();//没用ob_start的可以去掉
flush();
$BytesSent+=$ReadBuffer;
}
return true;
}
/**
*
*/
function send_link($Source,$Destinaion,$VaildTime){
$TmpDownloadPath='./tmp/';
if($VaildTime>0){
foreach(glob($TmpDownloadPath.'*.*') as $File){
if(filemtime($File) < (time()-($VaildTime*60*60))){
$this->_unlink($File);
}
}
}
if(file_exists($Destinaion)){
header("HTTP/1.1 301 Moved Permanently");
header("Location: {$TmpDownloadPath}{$Destinaion}");
}else{
$this->_symlink($Source,$TmpDownloadPath.$Destinaion);
header("HTTP/1.1 301 Moved Permanently");
header("Location: {$TmpDownloadPath}{$Destinaion}");
}
}
/**
* 在Win下需要linkd跟Web用户对linkd,cmd有执行的权限并可执行exec函数,并且是NTFS格式
* linkd下载地址:
* http://www.dynawell.com/reskit/microsoft/win2000/linkd.zip
* 注意在php安全模式下需要把linkd,cmd放到safe_mode_exec_dir指定的目录下
*/
function _symlink($Source,$Destination){
if(strtoupper(PHP_OS) == 'WINNT'){
$LinkExec="linkd";
return (function_exists('exec') && file_exists($Source))?exec("$LinkExec \"$Destination\" \"$Source\""):false;
}else{
return symlink($Source,$Destination);
}
}
//删除有_symlink创建的文件
//注意:见_symlink函数注释
function _unlink($Source){
if(strtoupper(PHP_OS) == 'WINNT'){
$LinkExec="linkd";
return (function_exists('exec') && file_exists($Source))?
exec("$LinkExec -d \"$Source\""):false;
}else{
unlink($Source);
}
}
/**
* 发送函数,(下载可简单的防盗链)
* 支持的方式有symlink(高并发),sendfile(低并发).
* sendfile函数大都从Legend的[php]一个发送文件的函数得来.
* 详见:http://www.ugia.cn/?p=109
* thanks legend...
* 备注:可自行修改检测功能增强防盗
*/
function send($Source,$Destination,$Method='file',$Check=true,$VaildTime=24,$AllowPartial=true){
if(!is_readable($Source)){
header("HTTP/1.1 404 Not Found");
echo "<html><head><meta http-equiv='refresh' content='0; url=/'></head></html>";
return false;
}
if($Check){
$Deny=false;
$CheckKey=isset($_GET['LINKFIREWALL'])?$_GET['LINKFIREWALL']:$_COOKIE['LINKFIREWALL'];
preg_match('/[^\.]+\.([^\.]+).*/i',$_SERVER['HTTP_HOST'],$Tmp);
$Domain=$Tmp[1];
preg_match('/:[^\.]+\.([^\.]+).*/i',$_SERVER['HTTP_REFERER'],$Tmp);
$Referer=$Tmp[1];
$Key=md5('Password'.$Domain);
if(empty($CheckKey)||($CheckKey!=$Key)||($Domain!=$Referer)){
header("HTTP/1.1 404 Not Found");
exit("<html><head><meta http-equiv='refresh' content='3; url=/'></head><body>请不要盗链本站资源</body></html>");
}
}
if(strtoupper($Method)=='LINK'){
$this->send_link($Source,$Destination,$VaildTime);
}else{
$this->send_file($Source,$Destination,$AllowPartial);
}
}
function mime_type($Filename,$Unknow='octet-stream'){
$MIMETYPE=array("323"=>"text/h323","acx"=>"application/internet-property-stream","ai"=>"application/postscript","aif"=>"audio/x-aiff","aifc"=>"audio/x-aiff","aiff"=>"audio/x-aiff","asf"=>"video/x-ms-asf","asr"=>"video/x-ms-asf","asx"=>"video/x-ms-asf","au"=>"audio/basic", "avi"=>"video/x-msvideo","axs"=>"application/olescript","bas"=>"text/plain","bcpio"=>"application/x-bcpio","bin"=>"application/octet-stream","bmp"=>"image/bmp","c"=>"text/plain","cat"=>"application/vnd.ms-pkiseccat","cdf"=>"application/x-cdf","cer"=>"application/x-x509-ca-cert","class"=>"application/octet-stream","clp"=>"application/x-msclip","cmx"=>"image/x-cmx","cod"=>"image/cis-cod","cpio"=>"application/x-cpio","crd"=>"application/x-mscardfile","crl"=>"application/pkix-crl","crt"=>"application/x-x509-ca-cert","csh"=>"application/x-csh","css"=>"text/css","dcr"=>"application/x-director","der"=>"application/x-x509-ca-cert","dir"=>"application/x-director","dll"=>"application/x-msdownload","dms"=>"application/octet-stream","doc"=>"application/msword","dot"=>"application/msword","dvi"=>"application/x-dvi","dxr"=>"application/x-director","eps"=>"application/postscript","etx"=>"text/x-setext","evy"=>"application/envoy","exe"=>"application/octet-stream","fif"=>"application/fractals","flr"=>"x-world/x-vrml","gif"=>"image/gif","gtar"=>"application/x-gtar","gz"=>"application/x-gzip","h"=>"text/plain","hdf"=>"application/x-hdf","hlp"=>"application/winhlp","hqx"=>"application/mac-binhex40","hta"=>"application/hta","htc"=>"text/x-component","htm"=>"text/html","html"=>"text/html","htt"=>"text/webviewhtml","ico"=>"image/x-icon","ief"=>"image/ief","iii"=>"application/x-iphone","ins"=>"application/x-internet-signup","isp"=>"application/x-internet-signup","jfif"=>"image/pipeg","jpe"=>"image/jpeg","jpeg"=>"image/jpeg","jpg"=>"image/jpeg","js"=>"application/x-javascript","latex"=>"application/x-latex","lha"=>"application/octet-stream","lsf"=>"video/x-la-asf","lsx"=>"video/x-la-asf","lzh"=>"application/octet-stream","m13"=>"application/x-msmediaview","m14"=>"application/x-msmediaview","m3u"=>"audio/x-mpegurl","man"=>"application/x-troff-man","mdb"=>"application/x-msaccess","me"=>"application/x-troff-me","mht"=>"message/rfc822","mhtml"=>"message/rfc822","mid"=>"audio/mid","mny"=>"application/x-msmoney","mov"=>"video/quicktime","movie"=>"video/x-sgi-movie","mp2"=>"video/mpeg","mp3"=>"audio/mpeg","mpa"=>"video/mpeg","mpe"=>"video/mpeg","mpeg"=>"video/mpeg","mpg"=>"video/mpeg","mpp"=>"application/vnd.ms-project","mpv2"=>"video/mpeg","ms"=>"application/x-troff-ms","mvb"=>"application/x-msmediaview","nws"=>"message/rfc822","oda"=>"application/oda","p10"=>"application/pkcs10","p12"=>"application/x-pkcs12","p7b"=>"application/x-pkcs7-certificates","p7c"=>"application/x-pkcs7-mime","p7m"=>"application/x-pkcs7-mime","p7r"=>"application/x-pkcs7-certreqresp","p7s"=>"application/x-pkcs7-signature","pbm"=>"image/x-portable-bitmap","pdf"=>"application/pdf","pfx"=>"application/x-pkcs12","pgm"=>"image/x-portable-graymap","pko"=>"application/ynd.ms-pkipko","pma"=>"application/x-perfmon","pmc"=>"application/x-perfmon","pml"=>"application/x-perfmon","pmr"=>"application/x-perfmon","pmw"=>"application/x-perfmon","pnm"=>"image/x-portable-anymap","pot,"=>"application/vnd.ms-powerpoint","ppm"=>"image/x-portable-pixmap","pps"=>"application/vnd.ms-powerpoint","ppt"=>"application/vnd.ms-powerpoint","prf"=>"application/pics-rules","ps"=>"application/postscript","pub"=>"application/x-mspublisher","qt"=>"video/quicktime","ra"=>"audio/x-pn-realaudio","ram"=>"audio/x-pn-realaudio","ras"=>"image/x-cmu-raster","rgb"=>"image/x-rgb","rmi"=>"audio/mid","roff"=>"application/x-troff","rtf"=>"application/rtf","rtx"=>"text/richtext","scd"=>"application/x-msschedule","sct"=>"text/scriptlet","setpay"=>"application/set-payment-initiation","setreg"=>"application/set-registration-initiation","sh"=>"application/x-sh","shar"=>"application/x-shar","sit"=>"application/x-stuffit","snd"=>"audio/basic","spc"=>"application/x-pkcs7-certificates","spl"=>"application/futuresplash","src"=>"application/x-wais-source","sst"=>"application/vnd.ms-pkicertstore","stl"=>"application/vnd.ms-pkistl","stm"=>"text/html","svg"=>"image/svg+xml","sv4cpio"=>"application/x-sv4cpio","sv4crc"=>"application/x-sv4crc","swf"=>"application/x-shockwave-flash","t"=>"application/x-troff","tar"=>"application/x-tar","tcl"=>"application/x-tcl","tex"=>"application/x-tex","texi"=>"application/x-texinfo","texinfo"=>"application/x-texinfo","tgz"=>"application/x-compressed","tif"=>"image/tiff","tiff"=>"image/tiff","tr"=>"application/x-troff","trm"=>"application/x-msterminal","tsv"=>"text/tab-separated-values","txt"=>"text/plain","uls"=>"text/iuls","ustar"=>"application/x-ustar","vcf"=>"text/x-vcard","vrml"=>"x-world/x-vrml","wav"=>"audio/x-wav","wcm"=>"application/vnd.ms-works","wdb"=>"application/vnd.ms-works","wks"=>"application/vnd.ms-works","wmf"=>"application/x-msmetafile","wps"=>"application/vnd.ms-works","wri"=>"application/x-mswrite","wrl"=>"x-world/x-vrml","wrz"=>"x-world/x-vrml","xaf"=>"x-world/x-vrml","xbm"=>"image/x-xbitmap","xla"=>"application/vnd.ms-excel","xlc"=>"application/vnd.ms-excel","xlm"=>"application/vnd.ms-excel","xls"=>"application/vnd.ms-excel","xlt"=>"application/vnd.ms-excel","xlw"=>"application/vnd.ms-excel","xof"=>"x-world/x-vrml","xpm"=>"image/x-xpixmap","xwd"=>"image/x-xwindowdump","z"=>"application/x-compress","zip"=>"application/zip","7z"=>"application/zip");
$Suffix=array_pop(explode('.',$Filename));
return array_key_exists($Suffix,$MIMETYPE)?$MIMETYPE[$Suffix]:$Unknow=='octet-stream'?'application/octet-stream':'application/unknow';
}
}
?>