php获取用户IP地址

具体请下载

<?php
require_once './Getip/qqwry.class.php';
$ip 		=	get_user_ip();
//$ip 		=	'58.61.214.48';
$QQWry		=	new QQWry;
$ifErr		=	$QQWry->QQWry($ip); 
$location	=	$QQWry->Country.$QQWry->Local;
if(!empty($location))
{
	$location =	iconv('GB2312', 'UTF-8', $location);
}
else
{
	$location = '未知地区';
}
 
 
/*
	 * 获取用户的Ip地址
	 */
	function get_user_ip()
    {
		/*
	        if($_SERVER["HTTP_X_REAL_IP"])
			{
				$ip	=	$_SERVER["HTTP_X_REAL_IP"];
			}
			else
		*/
		if($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"])
        {                                             
               $ip = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
        }                                             
        elseif($HTTP_SERVER_VARS["HTTP_CLIENT_IP"])   
        {                                             
               $ip = $HTTP_SERVER_VARS["HTTP_CLIENT_IP"];
        }                                             
        elseif ($HTTP_SERVER_VARS["REMOTE_ADDR"])      
        {                                             
               $ip = $HTTP_SERVER_VARS["REMOTE_ADDR"];  
        }                                             
        elseif (getenv("HTTP_X_FORWARDED_FOR"))          
        {                                             
               $ip = getenv("HTTP_X_FORWARDED_FOR");  
        }                                             
        elseif (getenv("HTTP_CLIENT_IP"))                
        {                                             
               $ip = getenv("HTTP_CLIENT_IP");  
        }         
        elseif (getenv("REMOTE_ADDR"))  {                                             
               $ip = getenv("REMOTE_ADDR");
        }      
        else    {                                             
               $ip = "Unknown";   
        } 
 
        return $ip;
    }
?>
<div style='font-size:18px;font-weight: 500;font-family: "microsoft yahei";margin-top:10px;'>
                    我的IP地址:<?php echo $ip; ?><br /><br />
                    所属地区:&nbsp;&nbsp;<?php echo $location; ?>
</div>

PHP 汉字转拼音URL

想要一个汉字转拼音URL的功能,于是在这里找到了http://hahaxiao.techweb.com.cn/archives/750.html,但是它只是把汉字转换为拼音,不能生成wo-ai-ni这样的URL格式,所以我小小的改动了一下。
源代码来自:http://hahaxiao.techweb.com.cn/archives/750.html

<?php
/**
*
* 中文转换为拼音
*
*/
function cn2pinyin($_String, $_Code='gb2312') 
{
	$_DataKey = "a|ai|an|ang|ao|ba|bai|ban|bang|bao|bei|ben|beng|bi|bian|biao|bie|bin|bing|bo|bu|ca|cai|can|cang|cao|ce|ceng|cha" .
	"|chai|chan|chang|chao|che|chen|cheng|chi|chong|chou|chu|chuai|chuan|chuang|chui|chun|chuo|ci|cong|cou|cu|" .
	"cuan|cui|cun|cuo|da|dai|dan|dang|dao|de|deng|di|dian|diao|die|ding|diu|dong|dou|du|duan|dui|dun|duo|e|en|er" .
	"|fa|fan|fang|fei|fen|feng|fo|fou|fu|ga|gai|gan|gang|gao|ge|gei|gen|geng|gong|gou|gu|gua|guai|guan|guang|gui" .
	"|gun|guo|ha|hai|han|hang|hao|he|hei|hen|heng|hong|hou|hu|hua|huai|huan|huang|hui|hun|huo|ji|jia|jian|jiang" .
	"|jiao|jie|jin|jing|jiong|jiu|ju|juan|jue|jun|ka|kai|kan|kang|kao|ke|ken|keng|kong|kou|ku|kua|kuai|kuan|kuang" .
	"|kui|kun|kuo|la|lai|lan|lang|lao|le|lei|leng|li|lia|lian|liang|liao|lie|lin|ling|liu|long|lou|lu|lv|luan|lue" .
	"|lun|luo|ma|mai|man|mang|mao|me|mei|men|meng|mi|mian|miao|mie|min|ming|miu|mo|mou|mu|na|nai|nan|nang|nao|ne" .
	"|nei|nen|neng|ni|nian|niang|niao|nie|nin|ning|niu|nong|nu|nv|nuan|nue|nuo|o|ou|pa|pai|pan|pang|pao|pei|pen" .
	"|peng|pi|pian|piao|pie|pin|ping|po|pu|qi|qia|qian|qiang|qiao|qie|qin|qing|qiong|qiu|qu|quan|que|qun|ran|rang" .
	"|rao|re|ren|reng|ri|rong|rou|ru|ruan|rui|run|ruo|sa|sai|san|sang|sao|se|sen|seng|sha|shai|shan|shang|shao|" .
	"she|shen|sheng|shi|shou|shu|shua|shuai|shuan|shuang|shui|shun|shuo|si|song|sou|su|suan|sui|sun|suo|ta|tai|" .
	"tan|tang|tao|te|teng|ti|tian|tiao|tie|ting|tong|tou|tu|tuan|tui|tun|tuo|wa|wai|wan|wang|wei|wen|weng|wo|wu" .
	"|xi|xia|xian|xiang|xiao|xie|xin|xing|xiong|xiu|xu|xuan|xue|xun|ya|yan|yang|yao|ye|yi|yin|ying|yo|yong|you" .
	"|yu|yuan|yue|yun|za|zai|zan|zang|zao|ze|zei|zen|zeng|zha|zhai|zhan|zhang|zhao|zhe|zhen|zheng|zhi|zhong|" .
	"zhou|zhu|zhua|zhuai|zhuan|zhuang|zhui|zhun|zhuo|zi|zong|zou|zu|zuan|zui|zun|zuo";
	$_DataValue = "-20319|-20317|-20304|-20295|-20292|-20283|-20265|-20257|-20242|-20230|-20051|-20036|-20032|-20026|-20002|-19990" .
	"|-19986|-19982|-19976|-19805|-19784|-19775|-19774|-19763|-19756|-19751|-19746|-19741|-19739|-19728|-19725" .
	"|-19715|-19540|-19531|-19525|-19515|-19500|-19484|-19479|-19467|-19289|-19288|-19281|-19275|-19270|-19263" .
	"|-19261|-19249|-19243|-19242|-19238|-19235|-19227|-19224|-19218|-19212|-19038|-19023|-19018|-19006|-19003" .
	"|-18996|-18977|-18961|-18952|-18783|-18774|-18773|-18763|-18756|-18741|-18735|-18731|-18722|-18710|-18697" .
	"|-18696|-18526|-18518|-18501|-18490|-18478|-18463|-18448|-18447|-18446|-18239|-18237|-18231|-18220|-18211" .
	"|-18201|-18184|-18183|-18181|-18012|-17997|-17988|-17970|-17964|-17961|-17950|-17947|-17931|-17928|-17922" .
	"|-17759|-17752|-17733|-17730|-17721|-17703|-17701|-17697|-17692|-17683|-17676|-17496|-17487|-17482|-17468" .
	"|-17454|-17433|-17427|-17417|-17202|-17185|-16983|-16970|-16942|-16915|-16733|-16708|-16706|-16689|-16664" .
	"|-16657|-16647|-16474|-16470|-16465|-16459|-16452|-16448|-16433|-16429|-16427|-16423|-16419|-16412|-16407" .
	"|-16403|-16401|-16393|-16220|-16216|-16212|-16205|-16202|-16187|-16180|-16171|-16169|-16158|-16155|-15959" .
	"|-15958|-15944|-15933|-15920|-15915|-15903|-15889|-15878|-15707|-15701|-15681|-15667|-15661|-15659|-15652" .
	"|-15640|-15631|-15625|-15454|-15448|-15436|-15435|-15419|-15416|-15408|-15394|-15385|-15377|-15375|-15369" .
	"|-15363|-15362|-15183|-15180|-15165|-15158|-15153|-15150|-15149|-15144|-15143|-15141|-15140|-15139|-15128" .
	"|-15121|-15119|-15117|-15110|-15109|-14941|-14937|-14933|-14930|-14929|-14928|-14926|-14922|-14921|-14914" .
	"|-14908|-14902|-14894|-14889|-14882|-14873|-14871|-14857|-14678|-14674|-14670|-14668|-14663|-14654|-14645" .
	"|-14630|-14594|-14429|-14407|-14399|-14384|-14379|-14368|-14355|-14353|-14345|-14170|-14159|-14151|-14149" .
	"|-14145|-14140|-14137|-14135|-14125|-14123|-14122|-14112|-14109|-14099|-14097|-14094|-14092|-14090|-14087" .
	"|-14083|-13917|-13914|-13910|-13907|-13906|-13905|-13896|-13894|-13878|-13870|-13859|-13847|-13831|-13658" .
	"|-13611|-13601|-13406|-13404|-13400|-13398|-13395|-13391|-13387|-13383|-13367|-13359|-13356|-13343|-13340" .
	"|-13329|-13326|-13318|-13147|-13138|-13120|-13107|-13096|-13095|-13091|-13076|-13068|-13063|-13060|-12888" .
	"|-12875|-12871|-12860|-12858|-12852|-12849|-12838|-12831|-12829|-12812|-12802|-12607|-12597|-12594|-12585" .
	"|-12556|-12359|-12346|-12320|-12300|-12120|-12099|-12089|-12074|-12067|-12058|-12039|-11867|-11861|-11847" .
	"|-11831|-11798|-11781|-11604|-11589|-11536|-11358|-11340|-11339|-11324|-11303|-11097|-11077|-11067|-11055" .
	"|-11052|-11045|-11041|-11038|-11024|-11020|-11019|-11018|-11014|-10838|-10832|-10815|-10800|-10790|-10780" .
	"|-10764|-10587|-10544|-10533|-10519|-10331|-10329|-10328|-10322|-10315|-10309|-10307|-10296|-10281|-10274" .
	"|-10270|-10262|-10260|-10256|-10254";
	$_TDataKey = explode('|', $_DataKey);
	$_TDataValue = explode('|', $_DataValue);
	$_Data = (PHP_VERSION >= '5.0') ? array_combine($_TDataKey, $_TDataValue) : _Array_Combine($_TDataKey, $_TDataValue);
	arsort($_Data);
	reset($_Data);
	if ($_Code != 'gb2312')
	$_String = _U2_Utf8_Gb($_String);
	$_Res = '';
	for ($i = 0; $i < strlen($_String); $i++) 
	{
		$_P = ord(substr($_String, $i, 1));
		if ($_P > 160) 
		{
			$_Q = ord(substr($_String, ++$i, 1));
			$_P = $_P * 256 + $_Q - 65536;
		}
		$_Res .= _Pinyin($_P, $_Data);
	}
	//echo $_Res;
	$_Res = preg_replace("/[^a-z0-9\s]*/", '', $_Res);   //此处有改动
	return $_Res = preg_replace("/\s/", '-', $_Res);     //此处有改动
}
 
function _Pinyin($_Num, $_Data) 
{
	if ($_Num > 0 && $_Num < 160)
	return chr($_Num);
	elseif ($_Num < -20319 || $_Num > -10247)
	return '';
	else {
	foreach ($_Data as $k => $v) {
	if ($v <= $_Num)
	break;
	}
	return $k;
	}
}
function _U2_Utf8_Gb($_C) 
{
	$_String = '';
	if ($_C < 0x80)
	$_String .= $_C;
	elseif ($_C < 0x800) {
	$_String .= chr(0xC0 | $_C >> 6);
	$_String .= chr(0x80 | $_C & 0x3F);
	} elseif ($_C < 0x10000) {
	$_String .= chr(0xE0 | $_C >> 12);
	$_String .= chr(0x80 | $_C >> 6 & 0x3F);
	$_String .= chr(0x80 | $_C & 0x3F);
	} elseif ($_C < 0x200000) {
	$_String .= chr(0xF0 | $_C >> 18);
	$_String .= chr(0x80 | $_C >> 12 & 0x3F);
	$_String .= chr(0x80 | $_C >> 6 & 0x3F);
	$_String .= chr(0x80 | $_C & 0x3F);
	}
	return iconv('UTF-8', 'GB2312', $_String);
}
function _Array_Combine($_Arr1, $_Arr2) 
{
	for ($i = 0; $i < count($_Arr1); $i++)
	$_Res[$_Arr1[$i]] = $_Arr2[$i];
	return $_Res;
}
echo cn2pinyin('zhangsan\'s google 李四',1);

php全功能无变形图片裁剪(转)

转载自:http://hi.baidu.com/microji/item/548d23dbfda6d93be2108f03

很久以前写了一个php图片任意图片无变形裁剪到指定大小,发布在CSDN博客上,后来被phpchina采集去了,程序有明显漏洞,现在修改了一下,在扩展一些功能,如果需要图片裁剪,或生成缩略图,这个基本上没有问题,全部需要的功能都在里面,全部都是无变形的。

这里我划分为四种模式:
1,任意图片裁剪到指定大小,超过的,剧中裁剪,并且最大化缩放,不够的拉伸,
2,超过的剧中裁剪,而不足的,不拉伸,即只缩小,不放大裁剪,会产生补白,可以用png透明度来消除
3,保留全部图片信息。不裁剪,只缩放,不足的补白。
4,保留全部图片信息。不裁剪,只缩放,不足的不补白,产生的图片为实际有效像素大小,例如有个图片是600X600 现在要生成 120X100 那么缩放后的实际有效像素为100X100,所以只生成100X100的图片,而第三种模式则生成120X100的大小,并且有补白

全部代码:

<?php
 
 
/**
* Author : smallchicken
* Time   : 2009年6月8日16:46:05
* mode 1 : 强制裁剪,生成图片严格按照需要,不足放大,超过裁剪,图片始终铺满
* mode 2 : 和1类似,但不足的时候 不放大 会产生补白,可以用png消除。
* mode 3 : 只缩放,不裁剪,保留全部图片信息,会产生补白,
* mode 4 : 只缩放,不裁剪,保留全部图片信息,生成图片大小为最终缩放后的图片有效信息的实际大小,不产生补白
* 默认补白为白色,如果要使补白成透明像素,请使用SaveAlpha()方法代替SaveImage()方法
*
* 调用方法:
*
* $ic=new ImageCrop('old.jpg','afterCrop.jpg');
* $ic->Crop(120,80,2);
* $ic->SaveImage();
*        //$ic->SaveAlpha();将补白变成透明像素保存
* $ic->destory();
* 
*
*/
class ImageCrop{
 
var $sImage;
var $dImage;
var $src_file;
var $dst_file;
var $src_width;
var $src_height;
var $src_ext;
var $src_type;
 
function ImageCrop($src_file,$dst_file=''){
$this->src_file=$src_file;
$this->dst_file=$dst_file;
$this->LoadImage();
}
 
function SetSrcFile($src_file){
$this->src_file=$src_file;
}
 
function SetDstFile($dst_file){
$this->dst_file=$dst_file;
}
 
function LoadImage(){
list($this->src_width, $this->src_height, $this->src_type) = getimagesize($this->src_file);
switch($this->src_type) {
case IMAGETYPE_JPEG :
$this->sImage=imagecreatefromjpeg($this->src_file);
$this->ext='jpg';
break;
case IMAGETYPE_PNG :
$this->sImage=imagecreatefrompng($this->src_file);
$this->ext='png';
break;
case IMAGETYPE_GIF :
$this->sImage=imagecreatefromgif($this->src_file);
$this->ext='gif';
break;
default:
exit();
}
}
 
function SaveImage($fileName=''){
$this->dst_file=$fileName ? $fileName : $this->dst_file;
switch($this->src_type) {
case IMAGETYPE_JPEG :
imagejpeg($this->dImage,$this->dst_file,100);
break;
case IMAGETYPE_PNG :
imagepng($this->dImage,$this->dst_file);
break;
case IMAGETYPE_GIF :
imagegif($this->dImage,$this->dst_file);
break;
default:
break;
}
}
 
function OutImage(){
switch($this->src_type) {
case IMAGETYPE_JPEG :
header('Content-type: image/jpeg');
imagejpeg($this->dImage);
break;
case IMAGETYPE_PNG :
header('Content-type: image/png');
imagepng($this->dImage);
break;
case IMAGETYPE_GIF :
header('Content-type: image/gif');
imagegif($this->dImage);
break;
default:
break;
}
}
 
function SaveAlpha($fileName=''){
$this->dst_file=$fileName ? $fileName . '.png' : $this->dst_file .'.png';
imagesavealpha($this->dImage, true);
imagepng($this->dImage,$this->dst_file);
}
 
function OutAlpha(){
imagesavealpha($this->dImage, true);
header('Content-type: image/png');
imagepng($this->dImage);
}    
 
function destory(){
imagedestroy($this->sImage);
imagedestroy($this->dImage);
}
 
function Crop($dst_width,$dst_height,$mode=1,$dst_file=''){
if($dst_file) $this->dst_file=$dst_file;
$this->dImage = imagecreatetruecolor($dst_width,$dst_height);
 
$bg = imagecolorallocatealpha($this->dImage,255,255,255,127);
imagefill($this->dImage, 0, 0, $bg);
imagecolortransparent($this->dImage,$bg);
 
$ratio_w=1.0 * $dst_width / $this->src_width;
$ratio_h=1.0 * $dst_height / $this->src_height;
$ratio=1.0;
switch($mode){
case 1:        // always crop
if( ($ratio_w < 1 && $ratio_h < 1) || ($ratio_w > 1 && $ratio_h > 1)){
$ratio = $ratio_w < $ratio_h ? $ratio_h : $ratio_w;
$tmp_w = (int)($dst_width / $ratio);
$tmp_h = (int)($dst_height / $ratio);
$tmp_img=imagecreatetruecolor($tmp_w , $tmp_h);
$src_x = (int) (($this->src_width-$tmp_w)/2) ; 
$src_y = (int) (($this->src_height-$tmp_h)/2) ;    
imagecopy($tmp_img, $this->sImage, 0,0,$src_x,$src_y,$tmp_w,$tmp_h);    
imagecopyresampled($this->dImage,$tmp_img,0,0,0,0,$dst_width,$dst_height,$tmp_w,$tmp_h);
imagedestroy($tmp_img);
}else{
$ratio = $ratio_w < $ratio_h ? $ratio_h : $ratio_w;
$tmp_w = (int)($this->src_width * $ratio);
$tmp_h = (int)($this->src_height * $ratio);
$tmp_img=imagecreatetruecolor($tmp_w ,$tmp_h);
imagecopyresampled($tmp_img,$this->sImage,0,0,0,0,$tmp_w,$tmp_h,$this->src_width,$this->src_height);
$src_x = (int)($tmp_w - $dst_width) / 2 ; 
$src_y = (int)($tmp_h - $dst_height) / 2 ;    
imagecopy($this->dImage, $tmp_img, 0,0,$src_x,$src_y,$dst_width,$dst_height);
imagedestroy($tmp_img);
}
break;
case 2:        // only small
if($ratio_w < 1 && $ratio_h < 1){
$ratio = $ratio_w < $ratio_h ? $ratio_h : $ratio_w;
$tmp_w = (int)($dst_width / $ratio);
$tmp_h = (int)($dst_height / $ratio);
$tmp_img=imagecreatetruecolor($tmp_w , $tmp_h);
$src_x = (int) ($this->src_width-$tmp_w)/2 ; 
$src_y = (int) ($this->src_height-$tmp_h)/2 ;    
imagecopy($tmp_img, $this->sImage, 0,0,$src_x,$src_y,$tmp_w,$tmp_h);    
imagecopyresampled($this->dImage,$tmp_img,0,0,0,0,$dst_width,$dst_height,$tmp_w,$tmp_h);
imagedestroy($tmp_img);
}elseif($ratio_w > 1 && $ratio_h > 1){
$dst_x = (int) abs($dst_width - $this->src_width) / 2 ; 
$dst_y = (int) abs($dst_height -$this->src_height) / 2;    
imagecopy($this->dImage, $this->sImage,$dst_x,$dst_y,0,0,$this->src_width,$this->src_height);
}else{
$src_x=0;$dst_x=0;$src_y=0;$dst_y=0;
if(($dst_width - $this->src_width) < 0){
$src_x = (int) ($this->src_width - $dst_width)/2;
$dst_x =0;
}else{
$src_x =0;
$dst_x = (int) ($dst_width - $this->src_width)/2;
}
 
if( ($dst_height -$this->src_height) < 0){
$src_y = (int) ($this->src_height - $dst_height)/2;
$dst_y = 0;
}else{
$src_y = 0;
$dst_y = (int) ($dst_height - $this->src_height)/2;
}
imagecopy($this->dImage, $this->sImage,$dst_x,$dst_y,$src_x,$src_y,$this->src_width,$this->src_height);
}
break;
case 3:        // keep all image size and create need size
if($ratio_w > 1 && $ratio_h > 1){
$dst_x = (int)(abs($dst_width - $this->src_width )/2) ; 
$dst_y = (int)(abs($dst_height- $this->src_height)/2) ;
imagecopy($this->dImage, $this->sImage, $dst_x,$dst_y,0,0,$this->src_width,$this->src_height);
}else{
$ratio = $ratio_w > $ratio_h ? $ratio_h : $ratio_w;
$tmp_w = (int)($this->src_width * $ratio);
$tmp_h = (int)($this->src_height * $ratio);
$tmp_img=imagecreatetruecolor($tmp_w ,$tmp_h);
imagecopyresampled($tmp_img,$this->sImage,0,0,0,0,$tmp_w,$tmp_h,$this->src_width,$this->src_height);
$dst_x = (int)(abs($tmp_w -$dst_width )/2) ; 
$dst_y = (int)(abs($tmp_h -$dst_height)/2) ;
imagecopy($this->dImage, $tmp_img, $dst_x,$dst_y,0,0,$tmp_w,$tmp_h);
imagedestroy($tmp_img);
}
break;
case 4:        // keep all image but create actually size
if($ratio_w > 1 && $ratio_h > 1){
$this->dImage = imagecreatetruecolor($this->src_width,$this->src_height);
imagecopy($this->dImage, $this->sImage,0,0,0,0,$this->src_width,$this->src_height);
}else{
$ratio = $ratio_w > $ratio_h ? $ratio_h : $ratio_w;
$tmp_w = (int)($this->src_width * $ratio);
$tmp_h = (int)($this->src_height * $ratio);
$this->dImage = imagecreatetruecolor($tmp_w ,$tmp_h);
imagecopyresampled($this->dImage,$this->sImage,0,0,0,0,$tmp_w,$tmp_h,$this->src_width,$this->src_height);
}
break;
}
}// end Crop
 
 
}
?>

PHP UNZIP

一款在线解压ZIP包的PHP文件,把这个文件上传到服务器即可解压服务器上的ZIP文件。

<?php
error_reporting(0);
//设定密码
$password = "123";
 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://gmpg.org/xfn/11">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="Content-Language" content="zh-CN" />
    <title>在线解压ZIP - PhpUnZip</title>
    <style type="text/css">
    <!--
    body {
        margin:0;
        padding:0;
        background:#ccc;
        font:14px/24px "Microsoft Yahei",Verdana, Geneva, sans-serif
    }
    #wrapper {
        width:760px;
        margin:0 auto;
        margin-top:10px;
        background:#fff;
        border:1px solid #888;
    }
    #header {
        background:#f7f7f7;
    }
    #header h1 {
        font:20px/30px Verdana, Geneva, sans-serif;
        font-weight:bold;
        text-shadow:0 0 1px #DDD;
        text-align:center;
    }
    #main {
        margin:20px;
    }
    #footer {
        text-align:center;
        font-size:12px;
        color:#666;
        border-top:1px solid #ccc;
        position:relative;
    }
    #footer a {
        text-decoration:none;
        color:#666;
    }
    #footer a:hover {
        text-decoration:underline;
    }
    #eincy {
        width:82px;
        height:36px;
        background:url(http://www.eincy.com/logo/s.png);
        position:absolute;
        right:3px;
        top:3px;
    }
    -->
    </style>
</head>
<body>
<div id="wrapper">
    <div id="header">
        <h1>PHP在线解压ZIP工具 - PHPUnZip</h1>
    </div>
    <div id="main">
        <form name="myform" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" enctype="multipart/form-data" onSubmit="return check_uploadObject(this);">
            <?php
                if(!$_REQUEST["myaction"]):
            ?>
 
            <script language="javascript">
            function check_uploadObject(form){
                if(form.password.value==''){
                    alert('请输入密码.');
                    return false;
                }
                return true;
            }
            </script>
        <p id="choose"> 
            选择ZIP文件:
            <select name="zipfile">
            <option value="" selected>- 请选择 -</option>
            <?php
                $fdir = opendir('./');
                while($file=readdir($fdir)){
                    if(!is_file($file)) continue;
                    if(preg_match('/\.zip$/mis',$file)){
                        echo "<option value='$file'>$file</option>\r\n";
                    }
                }
            ?>
            </select>
            或上传文件: <input name="upfile" type="file" id="upfile" size="20">
        </p>
        <p id="dir">
            解压到目录: <input name="todir" type="text" id="todir" value="" size="15"> 
                  (留空为本目录,必须有写入权限)
        </p>
        <p id="password">
            验证密码:<input name="password" type="password" id="password" size="15"> 
        </p>
        <p id="unzip">
            <input name="myaction" type="hidden" id="myaction" value="dounzip">
            <input type="submit" name="Submit" value=" 解 压 ">
        </p>
        <?php
 
        elseif($_REQUEST["myaction"]=="dounzip"):
 
 
        class zip
        {
 
         var $total_files = 0;
         var $total_folders = 0; 
 
         function Extract ( $zn, $to, $index = Array(-1) )
         {
           $ok = 0; $zip = @fopen($zn,'rb');
           if(!$zip) return(-1);
           $cdir = $this->ReadCentralDir($zip,$zn);
           $pos_entry = $cdir['offset'];
 
           if(!is_array($index)){ $index = array($index);  }
           for($i=0; $index[$i];$i++){
                if(intval($index[$i])!=$index[$i]||$index[$i]>$cdir['entries'])
                return(-1);
           }
           for ($i=0; $i<$cdir['entries']; $i++)
           {
             @fseek($zip, $pos_entry);
             $header = $this->ReadCentralFileHeaders($zip);
             $header['index'] = $i; $pos_entry = ftell($zip);
             @rewind($zip); fseek($zip, $header['offset']);
             if(in_array("-1",$index)||in_array($i,$index))
                $stat[$header['filename']]=$this->ExtractFile($header, $to, $zip);
           }
           fclose($zip);
           return $stat;
         }
 
          function ReadFileHeader($zip)
          {
            $binary_data = fread($zip, 30);
            $data = unpack('vchk/vid/vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $binary_data);
 
            $header['filename'] = fread($zip, $data['filename_len']);
            if ($data['extra_len'] != 0) {
              $header['extra'] = fread($zip, $data['extra_len']);
            } else { $header['extra'] = ''; }
 
            $header['compression'] = $data['compression'];$header['size'] = $data['size'];
            $header['compressed_size'] = $data['compressed_size'];
            $header['crc'] = $data['crc']; $header['flag'] = $data['flag'];
            $header['mdate'] = $data['mdate'];$header['mtime'] = $data['mtime'];
 
            if ($header['mdate'] && $header['mtime']){
             $hour=($header['mtime']&0xF800)>>11;$minute=($header['mtime']&0x07E0)>>5;
             $seconde=($header['mtime']&0x001F)*2;$year=(($header['mdate']&0xFE00)>>9)+1980;
             $month=($header['mdate']&0x01E0)>>5;$day=$header['mdate']&0x001F;
             $header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year);
            }else{$header['mtime'] = time();}
 
            $header['stored_filename'] = $header['filename'];
            $header['status'] = "ok";
            return $header;
          }
 
         function ReadCentralFileHeaders($zip){
            $binary_data = fread($zip, 46);
            $header = unpack('vchkid/vid/vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $binary_data);
 
            if ($header['filename_len'] != 0)
              $header['filename'] = fread($zip,$header['filename_len']);
            else $header['filename'] = '';
 
            if ($header['extra_len'] != 0)
              $header['extra'] = fread($zip, $header['extra_len']);
            else $header['extra'] = '';
 
            if ($header['comment_len'] != 0)
              $header['comment'] = fread($zip, $header['comment_len']);
            else $header['comment'] = '';
 
            if ($header['mdate'] && $header['mtime'])
            {
              $hour = ($header['mtime'] & 0xF800) >> 11;
              $minute = ($header['mtime'] & 0x07E0) >> 5;
              $seconde = ($header['mtime'] & 0x001F)*2;
              $year = (($header['mdate'] & 0xFE00) >> 9) + 1980;
              $month = ($header['mdate'] & 0x01E0) >> 5;
              $day = $header['mdate'] & 0x001F;
              $header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year);
            } else {
              $header['mtime'] = time();
            }
            $header['stored_filename'] = $header['filename'];
            $header['status'] = 'ok';
            if (substr($header['filename'], -1) == '/')
              $header['external'] = 0x41FF0010;
            return $header;
         }
 
         function ReadCentralDir($zip,$zip_name){
            $size = filesize($zip_name);
 
            if ($size < 277) $maximum_size = $size;
            else $maximum_size=277;
 
            @fseek($zip, $size-$maximum_size);
            $pos = ftell($zip); $bytes = 0x00000000;
 
            while ($pos < $size){
                $byte = @fread($zip, 1); $bytes=($bytes << 8) | ord($byte);
                if ($bytes == 0x504b0506 or $bytes == 0x2e706870504b0506){ $pos++;break;} $pos++;
            }
 
            $fdata=fread($zip,18);
 
            $data=@unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size',$fdata);
 
            if ($data['comment_size'] != 0) $centd['comment'] = fread($zip, $data['comment_size']);
            else $centd['comment'] = ''; $centd['entries'] = $data['entries'];
            $centd['disk_entries'] = $data['disk_entries'];
            $centd['offset'] = $data['offset'];$centd['disk_start'] = $data['disk_start'];
            $centd['size'] = $data['size'];  $centd['disk'] = $data['disk'];
            return $centd;
          }
 
         function ExtractFile($header,$to,$zip){
            $header = $this->readfileheader($zip);
 
            if(substr($to,-1)!="/") $to.="/";
            if($to=='./') $to = ''; 
            $pth = explode("/",$to.$header['filename']);
            $mydir = '';
            for($i=0;$i<count($pth)-1;$i++){
                if(!$pth[$i]) continue;
                $mydir .= $pth[$i]."/";
                if((!is_dir($mydir) && @mkdir($mydir,0777)) || (($mydir==$to.$header['filename'] || ($mydir==$to && $this->total_folders==0)) && is_dir($mydir)) ){
                    @chmod($mydir,0777);
                    $this->total_folders ++;
                    echo "<br /><input name='dfile[]' type='checkbox' value='$mydir' checked> 目录: $mydir
        ";
                }
            }
 
            if(strrchr($header['filename'],'/')=='/') return;   
 
            if (!($header['external']==0x41FF0010)&&!($header['external']==16)){
                if ($header['compression']==0){
                    $fp = @fopen($to.$header['filename'], 'wb');
                    if(!$fp) return(-1);
                    $size = $header['compressed_size'];
 
                    while ($size != 0){
                        $read_size = ($size < 2048 ? $size : 2048);
                        $buffer = fread($zip, $read_size);
                        $binary_data = pack('a'.$read_size, $buffer);
                        @fwrite($fp, $binary_data, $read_size);
                        $size -= $read_size;
                    }
                    fclose($fp);
                    touch($to.$header['filename'], $header['mtime']);
                }else{
                    $fp = @fopen($to.$header['filename'].'.gz','wb');
                    if(!$fp) return(-1);
                    $binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($header['compression']),
                    Chr(0x00), time(), Chr(0x00), Chr(3));
 
                    fwrite($fp, $binary_data, 10);
                    $size = $header['compressed_size'];
 
                    while ($size != 0){
                        $read_size = ($size < 1024 ? $size : 1024);
                        $buffer = fread($zip, $read_size);
                        $binary_data = pack('a'.$read_size, $buffer);
                        @fwrite($fp, $binary_data, $read_size);
                        $size -= $read_size;
                    }
 
                    $binary_data = pack('VV', $header['crc'], $header['size']);
                    fwrite($fp, $binary_data,8); fclose($fp);
 
                    $gzp = @gzopen($to.$header['filename'].'.gz','rb') or die("Cette archive est compress閑");
                    if(!$gzp) return(-2);
                    $fp = @fopen($to.$header['filename'],'wb');
                    if(!$fp) return(-1);
                    $size = $header['size'];
 
                    while ($size != 0){
                        $read_size = ($size < 2048 ? $size : 2048);
                        $buffer = gzread($gzp, $read_size);
                        $binary_data = pack('a'.$read_size, $buffer);
                        @fwrite($fp, $binary_data, $read_size);
                        $size -= $read_size;
                    }
                    fclose($fp); gzclose($gzp);
 
                    touch($to.$header['filename'], $header['mtime']);
                    @unlink($to.$header['filename'].'.gz');
 
                }
            }
 
            $this->total_files ++;
            echo "<br /><input name='dfile[]' type='checkbox' value='$to$header[filename]' checked> 文件: $to$header[filename]
        ";
 
            return true;
         }
 
        // end class
        }
 
            set_time_limit(0);
 
            if ($_POST['password'] != $password) die("输入的密码不正确,请重新输入。");
            if(!$_POST["todir"]) $_POST["todir"] = ".";
            $z = new Zip;
            $have_zip_file = 0;
            function start_unzip($tmp_name,$new_name,$checked){
                global $_POST,$z,$have_zip_file;
                $upfile = array("tmp_name"=>$tmp_name,"name"=>$new_name);
                if(is_file($upfile[tmp_name])){
                    $have_zip_file = 1;
                    echo "
        正在解压: <br /><input name='dfile[]' type='checkbox' value='$upfile[name]' ".($checked?"checked":"")."> $upfile[name]
 
        ";
                    if(preg_match('/\.zip$/mis',$upfile[name])){
                        $result=$z->Extract($upfile[tmp_name],$_POST["todir"]);
                        if($result==-1){
                            echo "
        文件 $upfile[name] 错误.
        ";
                        }
                        echo "
        <br />完成,共建立 $z->total_folders 个目录,$z->total_files 个文件.
 
 
        ";
                    }else{
                        echo "
        $upfile[name] 不是 zip 文件.
 
        ";          
                    }
                    if(realpath($upfile[name])!=realpath($upfile[tmp_name])){
                        @unlink($upfile[name]);
                        rename($upfile[tmp_name],$upfile[name]);
                    }
                }
            }
            clearstatcache();
 
            start_unzip($_POST["zipfile"],$_POST["zipfile"],0);
            start_unzip($_FILES["upfile"][tmp_name],$_FILES["upfile"][name],1);
 
            if(!$have_zip_file){
                echo "
        请选择或上传文件.
        ";
            }
        ?>
        <input name="password" type="hidden" id="password" value="<?php echo $_POST['password'];?>">
        <input name="myaction" type="hidden" id="myaction" value="dodelete"><br />
        <input name="按钮" type="button" value="返回" onClick="window.location='<?php echo $_SERVER['PHP_SELF'];?>';">
 
        <input type='button' value='反选' onclick='selrev();'> <input type='submit' onclick='return confirm("删除选定文件?");' value='删除选定'>
 
        <script language='javascript'>
        function selrev() {
            with(document.myform) {
                for(i=0;i<elements.length;i++) {
                    thiselm = elements[i];
                    if(thiselm.name.match(/dfile\[]/))  thiselm.checked = !thiselm.checked;
                }
            }
        }
        alert('完成.');
        </script>
        <?php
 
        elseif($_REQUEST["myaction"]=="dodelete"):
            set_time_limit(0);
            if ($_POST['password'] != $password) die("输入的密码不正确,请重新输入。");
 
            $dfile = $_POST["dfile"]; 
            echo "正在删除文件...
 
        ";
            if(is_array($dfile)){
                for($i=count($dfile)-1;$i>=0;$i--){
                    if(is_file($dfile[$i])){
                        if(@unlink($dfile[$i])){
                            echo "已删除文件: $dfile[$i]
        ";
                        }else{
                            echo "删除文件失败: $dfile[$i]
        ";
                        }
                    }else{
                        if(@rmdir($dfile[$i])){
                            echo "已删除目录: $dfile[$i]
        ";
                        }else{
                            echo "删除目录失败: $dfile[$i]
        ";
                        }               
                    }
 
                }
            }
            echo "
        完成.
 
        <input type='button' value='返回' onclick=\"window.location='".$_SERVER['PHP_SELF']."';\">
 
 
                 <script language='javascript'>('完成.');</script>";
 
        endif;
 
        ?>
          </form>
    </div>
    <div id="footer">
        <p>&copy; 2011 EinCy</p>
        <div id="eincy"></div>
    </div>
</div>
 
</body>
</html>

PHP FUNCTION FOR INTERCEPTION CHINESE

from: http://www.nowamagic.net/librarys/veda/detail/986

function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true)  
{  
    if(function_exists("mb_substr")){   
    if($suffix)   
      return mb_substr($str, $start, $length, $charset)."...";  
      else  
      return mb_substr($str, $start, $length, $charset);   
       }  
    elseif(function_exists('iconv_substr')) {  
        if($suffix)   
       return iconv_substr($str,$start,$length,$charset)."...";  
       else  
       return iconv_substr($str,$start,$length,$charset);  
    }  
    $re['utf-8']   = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";  
    $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";  
    $re['gbk']    = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";  
    $re['big5']   = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";  
    preg_match_all($re[$charset], $str, $match);  
    $slice = join("",array_slice($match[0], $start, $length));  
    if($suffix) return $slice."…";  
    return $slice;  
}