phpÎļþ²Ù×÷Àà
<?php
/**
* @]Class Name[= IO
* @]Class URI[= System.IO
* @]Purpose[=
* ±¾ÀàÓÃÓÚ¶ÔÎļþϵͳµÄ´¦Àí
* @]Author[= SNakeVil <51JS,BU,PHPx> (snakevil@qq.com)
* @]Version[= 1.1.1
* @]Create[= 17:13 2004-3-25
* @]Modifications[=
* 4:04 2004-3-30
* + ÐÞ¸´ generate_path() ·½·¨ÖдæÔÚµÄһЩ BUG
* + ÖØÐÂÉè¼Æ·½·¨ no_comment()
* 4:32 2004-3-29
* + ¼ò»¯·½·¨ list_dir() µÄ·µ»ØÖµ
* + Ôö¼Ó·½·¨ file_info() »ñÈ¡Îļþ»òĿ¼ÐÅÏ¢
* 5:35 2004-3-28
* + ÕûÀíÓÅ»¯Ëã·¨
* 7:31 2004-3-27
* + ½«´íÎó´¦Àí³éÏóΪ»ùÀà
* + Ôö¼Ó·½·¨ no_comment() ɾ³ýÎļþÖÐ C ¹æ·¶×¢ÊÍ
* @]See[=
*/
class IO extends SnkClass {
var $result; // ²Ù×÷·µ»Ø½á¹û£¬Èç·½·¨·µ»ØÖµÎª mixed£¬Ôò³É¹¦²Ù×÷½á¹û¿ÉÔÚ´Ë»ñµÃ
var $exec_cmd; // Ö´Ðз½·¨£¬ÔÝʱûӦÓõ½
var $exist_dir; // ´´½¨Ä¿Â¼Ê±×îºó´æÔÚµÄĿ¼£¬ÏÖÓÃÓÚ copy() ºÍ move()
var $buffer_size; // Îļþ¶ÁÈ¡»º³åÇø´óС£¬¸ù¾Ý·þÎñÓ¦ÓùæÄ£ºÍ·þÎñÆ÷ÅäÖÃÐ޸쬽¨ÒéĬÈÏÖµ
function IO() {
parent::SnkClass();
$this->result = array();
$this->exec_cmd = "";
$this->exist_dir = "";
$this->buffer_size = 8192;
return $this;
}
/**
* @]Method Name[= list_dir()
* @]Purpose[=
* ¶Áȡָ¶¨Ä¿Â¼ÄÚÈÝ£¬·µ»ØÄÚÈÝÊý×é
* @]Parameter[=
* string $dir_path Ö¸¶¨Ä¿Â¼Â·¾¶£¬Ä¬ÈÏΪµ±Ç°Ä¿Â¼
* @]Return[= mixed ´íÎó·µ»Ø FALSE£¬·ñÔò·µ»Ø
* array(
* array("name","location","type"),
* ......
* )
* @]Author[= SNakeVil <51JS,BU,PHPx> (snakevil@qq.com)
* @]See[=
*/
function list_dir($path=".") {
if (!is_dir($path)) return $this->error_occur(0x000B, __FUNCTION__);
if (!is_readable($path)) return $this->error_occur(0x0002, $path);
$dh = @opendir($path);
$result = array();
$path = realpath($path);
if ($path[strlen($path)-1]!=DIRECTORY_SEPARATOR) $path .= DIRECTORY_SEPARATOR; // ±£Ö¤Ä¿Â¼¾ø¶ÔµØÖ·ºó´øÄ¿Â¼·Ö¸ô·û
while (FALSE!==($fh=readdir($dh))) { // ʹÓà !== ·ÀÖ¹´¦ÀíÃû³ÆÎª 0 »ò FALSE µÄÎļþ¡¢Ä¿Â¼
if ($fh=="."||$fh=="..") continue; // ºöÂÔÏµÍ³ÌØ¶¨Îļþ¼Ð
$i = $path.$fh; // »ñÈ¡¾ø¶ÔµØÖ·
$t = array(
"name" => $fh,
"location" => $i,
"type" => is_file($i) ? 1 : (is_dir($i) ? 0 : -1)
);
$result[] = $t;
}
closedir($dh);
unset($dh, $fh, $t, $i);
clearstatcache(); // Çå³ýÎļþϵͳ»º´æ
return $this->result = $result;
}
/**
* @]Method Name[= file_info()
* @]Purpose[=
* »ñȡָ¶¨Îļþ»òĿ¼µÄÊôÐÔ
* @]Parameter[=
* string $dir_path Ö¸¶¨Ä¿Â¼Â·¾¶£¬Ä¬ÈÏΪµ±Ç°Ä¿Â¼
* @]Return[= mixed ´íÎó·µ»Ø FALSE£¬·ñÔò·µ»Ø
* array("name","location","type","size","access","change","modify","read","write"),
* @]Author[= SNakeVil <51JS,BU,PHPx> (snakevil@qq.com)
* @]See[=
*/
function file_info($path=".") {
$path = realpath($path);
if (!$path) return $this->error_occur(0x000A, __FUNCTION__);
$result = array(
"name" => substr($path, strrpos($path, DIRECTORY_SEPARATOR)+1),
"location" => $path,
"type" => is_file($path) ? 1 : (is_dir($path) ? 0 : -1),
"size" => filesize($path),
"access" => fileatime($path),
"modify" => filemtime($path),
"change" => filectime($path),
"read" => is_readable($path),
"write" => is_writeable($path)
);
clearstatcache();
return $this->result = $result;
}
/**
* @]Method Name[= seek_file()
* @]Purpose[=
* ¸ù¾ÝÕýÔò±í´ïʽÌõ¼þ£¬ÔÚÏàӦĿ¼¼°¸ø¶¨²ã´ÎµÄ×ÓĿ¼ÖÐËÑË÷Æ¥ÅäµÄÎļþ¡¢Ä¿Â¼
* @]Parameter[=
* string $pattern ¼æÈÝ PERL ±ê×¼µÄÕýÔò±í´ïʽָÃ÷ËÑË÷Æ¥ÅäÒªÇ󣬻áÌí¼Ó /^ $/£¬Ä¬ÈÏΪ .*
* string $path ½øÐÐËÑË÷µÄĿ¼·¾¶£¬Ä¬ÈÏΪµ±Ç°Â·¾¶
* enum $seesk_type ÓÐ -1 0 1 ÈýÖÖ¿ÉÄÜÖµ£¬0 ½öÎļþ¼Ð£¬1 ½öÎļþ£¬-1 Á½Õß¶¼°üÀ¨£¬Ä¬ÈÏΪ 1
* int $sub_dir ËÑË÷µÄ×ÓĿ¼Éî¶È£¬Ö¸¶¨Ä¿Â¼²»Ë㣬½¨Òé²»Òª³¬¹ý 5£¬Ä¬ÈÏΪ 0
* limit $limit ËÑË÷½á¹ûÏÞÖÆ£¬±ÜÃâ¹ý¶ÈÀË·Ñϵͳ×ÊÔ´£¬Ä¬ÈÏΪ 100
* @]Return[= mixed ´íÎó·µ»Ø FALSE£¬·ñÔò
* array(
* array(
* "name","locate","type"
* ),
* ......
* )
* @]Author[= SNakeVil <51JS,BU,PHPx> (snakevil@qq.com)
* @]See[=
*/
function seek_file($pattern=".*", $path=".", $seek_type=1, $sub_dir_level=0, $limit=100) {
/* ¼ì²é²ÎÊýÖµ */
$is_error = $seek_type!=1 && $seek_type!=0 && $seek_type!=-1;
$is_error = $is_error && (!is_int($sub_dir_level) || $sub_dir_level < 0);
$is_error = $is_error && (!is_int($limit) || $limit < 1);
if ($is_error) return $this->error_occur(0x000B, __FUNCTION__);
unset($is_error);
$result = array();
/* array() == FALSE£¬ËùÒÔÐèҪʹÓà === */
if (FALSE===$i=$this->list_dir($path)) return FALSE; // Èç¹û²»ÄÜÁоÙĿ¼£¬·µ»Ø
for ($j=0,$k=count($i);$j<$k;$j++) {
if ($i[$j]["type"]==-1) continue; // ¶ÔÓÚ·ÇĿ¼·ÇÎļþÏîÄ¿£¬Ìø¹ý
if ($i[$j]["type"]==0&&$sub_dir_level) { // Èç¹ûÐèÒªËÑË÷ϲãĿ¼
if (FALSE===$l=$this->seek_file($pattern,$i[$j]["location"],$seek_type,($sub_dir_level - 1),$limit)) return FALSE;
$result = array_merge($result, $l); // ½«Ï²ãĿ¼ËÑË÷½á¹ûÌí¼Ó
}
if ($seek_type+$i[$j]["type"]==1||!preg_match("/^".$pattern."$/", $i[$j]["name"])) continue; // Èç¹û²»ËÑË÷µ±Ç°ÀàÐÍ£¬Ìø¹ý
$result[] = $i[$j];
if (count($result)>=$limit) { // ½ØÈ¥³¬¹ýÒªÇóµÄ³¤¶È£¬À뿪ÁоÙ
array_splice($result, $limit);
break;
}
}
unset($i, $j, $k, $l);
return $this->result = $result;
}
/**
* @]Method Name[= delete()
* @]Purpose[=
* ɾ³ýÖ¸¶¨¶ÔÏó£¬Îļþ»òÎļþ¼Ð¡ª¡ª°üÀ¨ÄÚº¬×ÓĿ¼ºÍÎļþµÄ·Ç¿ÕÎļþ¼Ð
* @]Parameter[=
* string $path Ö¸¶¨ÒªÉ¾³ýµÄÄÚÈÝ·¾¶£¬Îļþ»òĿ¼¾ù¿É
* @]Return[= boolean ´íÎó·µ»Ø FALSE£¬·ñÔò TRUE
* @]Author[= SNakeVil <51JS,BU,PHPx> (snakevil@qq.com)
* @]See[=
*/
function delete($path="") {
$path = realpath($path);
if (!$path) return $this->error_occur(0x000A, __FUNCTION__);
if (!is_dir($path)) {
if (@unlink($path)) return TRUE; // Îļþɾ³ý³É¹¦
return $this->error_occur(0x0004, $path);
} else {
if (FALSE===$i=$this->list_dir($path)) return FALSE; // ²»ÄÜÁоÙĿ¼
for ($j=0,$k=count($i);$j<$k;$j++)
if (!$this->delete($i[$j]["location"])) return FALSE; // ɾ³ýĿ¼ÄÚÈݳö´í
unset($i, $j, $k);
return TRUE;
}
}
/**
* @]Method Name[= generate_path()
* @]Purpose[=
* »ñÈ¡ÏÖÓлò²»´æÔÚÎļþ¡¢Ä¿Â¼µÄ¾ø¶ÔµØÖ·
* @]Parameter[=
* string $path Òª»ñÈ¡µØÖ·µÄÎļþ¡¢Ä¿Â¼ÏÖÓÐÏà¶Ô¡¢¾ø¶ÔµØÖ·
* @]Return[= string »ñµÃµÄµØÖ·
* @]Author[= SNakeVil <51JS,BU,PHPx> (snakevil@qq.com)
* @]See[=
*/
function generate_path($path="") {
$i = "/"==DIRECTORY_SEPARATOR ? "\" : "/"; // ͳһĿ¼·Ö¸î·û
$path = str_replace($i, DIRECTORY_SEPARATOR, strval($path));
if ($path[strlen($path)-1]!=DIRECTORY_SEPARATOR) $path .= DIRECTORY_SEPARATOR;
$i = strpos($path, DIRECTORY_SEPARATOR); // »ñµÃ·¾¶ÖÐÊ׸öĿ¼·Ö¸î·ûµÄλÖÃ
$ext = substr($path, $i+1);
$path = substr($path, 0, $i+1);
if ($i=realpath($path)) $path = $i; // µÃµ½»ù±¾Â·¾¶
else {
$ext = $path.$ext;
$path = realpath(".");
}
if (strlen($ext)) { // ¶ÔÊ£ÓàÄÚÈÝ´¦Àí
$ext = preg_replace("/[:*?"<>|]/", "", explode(DIRECTORY_SEPARATOR, $ext));
array_pop($ext);
$path = explode(DIRECTORY_SEPARATOR, $path); // ½¨Á¢Ä¿Â¼²ãÖá
if ($path[count($path)-1]=="") array_pop($path);
while (count($ext)) {
$i = array_shift($ext);
if ($i==".."&&count($path)>1) array_pop($path);
elseif (""!=str_replace(".", "", $i)) $path[] = $i;
}
$path = implode(DIRECTORY_SEPARATOR, $path);
}
unset($ext, $i);
return $path;
}
/**
* @]Method Name[= make_dir()
* @]Purpose[=
* ½¨Á¢ÈÎÒâÎļþ¼Ð£¬Ïà¶Ô»ò¾ø¶Ô·¾¶½Ô¿É£¬Éî²ã½¨Á¢Òà¿É
* @]Parameter[=
* string $path Òª½¨Á¢µÄ×îÖÕĿ¼·¾¶
* @]Return[= boolean ´íÎó·µ»Ø FALSE£¬·ñÔò TRUE
* @]Author[= SNakeVil <51JS,BU,PHPx> (snakevil@qq.com)
* @]See[=
*/
function make_dir($path="") {
$i = explode(DIRECTORY_SEPARATOR, $this->generate_path($path)); // Éú³ÉĿ¼·¾¶
$path = array_shift($i);
for ($j=0,$k=count($i);$j<$k;$j++) {
$path .= DIRECTORY_SEPARATOR.$i[$j];
if (!is_dir($path)) {
if ($this->exist_dir=="") $this->exist_dir = $path; // ¼Ç¼×îºó´æÔÚµÄĿ¼·¾¶
if (!@mkdir($path)) return $this->error_occur(0x0003, substr($path, 0, strrpos($path, DIRECTORY_SEPARATOR)));
}
}
if ($this->exist_dir=="") $this->exist_dir = $path;
return TRUE;
}
/**
* @]Method Name[= verify_file()
* @]Purpose[=
* ʹÓà MD5 Ëã·¨±È½ÏÁ½¸öÎļþÊÇ·ñÏàͬ
* @]Parameter[=
* string $src Ô´Îļþ·¾¶
* string $dst Ä¿±êÎļþ·¾¶
* boolean $interal ¶ÔÓÚ³¬¹ý 1MB Îļþ£¬ÉèÖà FALSE ʡȥ MD5 ¼ìÑé²½Ö裬¼õÇá·þÎñÆ÷¸ºµ£
* @]Return[= boolean ´íÎó·µ»Ø FALSE£¬·ñÔò TRUE
* @]Author[= SNakeVil <51JS,BU,PHPx> (snakevil@qq.com)
* @]See[=
*/
function verify_file($src="", $dst="", $interal=TRUE) {
if (!is_file($src)||!is_file($dst)) return $this->error_occur(0x000B, __FUNCTION__);
if (!is_readable($src)) return $this->error_occur(0x0006, $src);
if (!is_readable($dst)) return $this->error_occur(0x0006, $dst);
$i = filesize($src);
if (filesize($dst)!=$i) { // Îļþ´óС²»µÈ
unset($i);
return FALSE;
}
if ($i>1024*1024*1024&&!$interal) { // ¶ÔÓÚ 1MB µÄÎļþ£¬Èç¹û²»ÒªÇó¾«È·¼ì²é£¬Ìø¹ý
unset($i);
return TRUE;
}
unset($i);
if (md5_file($src)!=md5_file($dst)) return FALSE; // Îļþ MD5 ЧÑé²»·ûºÏ£¬ÄÚÈݲ»Ïàͬ
return TRUE;
}
/**
* @]Method Name[= copy()
* @]Purpose[=
* ¶ÔÈÎÒâÎļþ¼Ð¡¢Îļþ½øÐи´ÖÆ£¬Ïà¶Ô»ò¾ø¶Ô·¾¶½Ô¿É£¬Îļþ¸´ÖÆÍê³Éºó»á½øÐÐЧÑ飬¼ì²éÊÇ·ñ³ö´íÊý¾Ý´íÎó
* @]Parameter[=
* string $src_path Ö¸¶¨Òª¸´ÖƵÄÔ´ÄÚÈÝ·¾¶£¬Îļþ»òĿ¼¾ù¿É
* string $dst_path Ö¸¶¨Òª¸´ÖƵÄÄ¿±êÄÚÈÝ·¾¶£¬Îļþ»òĿ¼¾ù¿É£¬ÐÔÖÊÓÉ $src_path ¾ö¶¨£¬¿ÉΪ $src_path ϲãĿ¼
* @]Return[= boolean ´íÎó·µ»Ø FALSE£¬·ñÔò TRUE
* @]Author[= SNakeVil <51JS,BU,PHPx> (snakevil@qq.com)
* @]See[=
*/
function copy($src="", $dst="", $sub=FALSE) {
if (!$src=realpath($src)) return $this->error_occur(0x000B, __FUNCTION__);
$dst = $this->generate_path($dst);
if (is_dir($src)) { // ´¦ÀíĿ¼
/*
* ¹ØÓÚËã·¨µÄ˵Ã÷£º
* ±¾À´´òËãʹÓúܼòµ¥µÄµÝ¹éËã·¨£¬ÓöÉñɱÉñ£¬ÓöħնħµÄ£¬ºóÀ´·¢ÏÖÒ»¸öÎÊÌ⣺Èç¹ûÄ¿±ê·¾¶
* ΪԴ·¾¶µÄºó´ú·¾¶Ôõô°ì£¿ÕâÑùËã·¨»á²»Í£µÄ̽²âÏÂÈ¥¡
* ÓÚÊÇÌí¼ÓÁË $this->exist_dir ÊôÐÔ£¬ÓÃÀ´¼Ç¼ÕâÒ»Çé¿öÏÂÄ¿±ê·¾¶ÖдæÔڵIJ¿·Ö¡£ÓÚÊÇеÄÎÊ
* Ìâ³öÀ´ÁË£ºÈçºÎ±£´æÕâÒ»ÊôÐÔ£¿
* ½«Õû¸ö¹¦ÄÜÕûºÏµ½ $this->copy() ·½·¨ÖУ¬ÄÇô±ØÈ»ÐèÒªÔÚÕâ¸öº¯ÊýÖмǼ $this->exist_dir
* µÄ±ä»¯£¬ÓÚÊǺõÐèÒªÁíÍâµÄÒ»¸öÓÐЧµÄ·½·¨À´×èֹÿһ´Î²Ù×÷ÖÐ¶ÔÆäµÄ¸ü¸Ä¡£
* ×÷Ϊ±äͨ£¬ÎÒʹÓõÄÒþ²Ø²ÎÊý $sub£¬Õâ¸ö²ÎÊýÎÞÂÛÈçºÎ£¬Ö»ÒªËã·¨²»±ä£¬ÓÀÔ¶ÔÚ²ÎÊý±íµÄ×î
* ºóÒ»¸ö¡£Òò´Ë£¬·½·¨¿ªÊ¼±äµÃ²»Îȶ¨£¬µ«ÕâҲûÓа취£¬Ö»ÄÜÏ£Íû³ÌÐòÔ±×Ô¼º²»Òª¹ÊÒâÆÆ»µ¡£
* ÔÚÍⲿµ÷ÓÃʱ£¬ÒòΪĬÈÏ FALSE£¬ËùÒÔ¶Ô $this->exist_dir д¡£ÄÚ²¿µÝ¹éʱ£¬ÏÔÐÔ TRUE£¬²»
* ¸ÃÊôÐÔ£¬±£Ö¤ÓÐЧÐÔ¡£
*/
if (!is_readable($src)) return $this->error_occur(0x0002, $src);
if ($dst[strlen($dst)-1]!=DIRECTORY_SEPARATOR) $dst .= DIRECTORY_SEPARATOR;
if (TRUE===$sub&&$src==$this->exist_dir) return TRUE; // Դ·¾¶Îª¼Ç¼µÄÄ¿±ê·¾¶
if (TRUE!==$sub) $this->exist_dir = ""; // ¼Ç¼´´½¨Ä¿Â¼Ç°Ä¿±êĿ¼·¾¶ÖдæÔÚµÄĿ¼·¾¶
if (!$this->make_dir($dst)) return FALSE; // ´´½¨Ä¿Â¼
if (FALSE===$i=$this->list_dir($src)) return FALSE; // ¶ÁȡĿ¼³ö´í
for ($j=0,$k=count($i);$j<$k;$j++) if (!$this->copy($i[$j]["location"], $dst.$i[$j]["name"],TRUE)) return FALSE;
unset($i, $j, $k);
RETURN TRUE;
} else {
if (!is_readable($src)) return $this->error_occur(0x0006, $src);
if ($this->verify_file($src,$dst)) return TRUE;
if (!copy($src,$dst)) return $this->error_occur(0x0007, $dst);
if (!$this->verify_file($src,$dst)) {
@unlink($dst); // ¸´ÖÆÎļþʧ°Üɾ³ýÐÂÎļþ
return $this->error_occur(0x0007, $dst);
}
return TRUE;
}
}
/**
* @]Method Name[= move()
* @]Purpose[=
* ¶ÔÈÎÒâÎļþ¼Ð¡¢Îļþ½øÐÐÒÆ¶¯£¬Ïà¶Ô»ò¾ø¶Ô·¾¶½Ô¿É£¬ÎļþÒÆ¶¯Íê³Éºó»á½øÐÐЧÑ飬¼ì²éÊÇ·ñ³ö´íÊý¾Ý´íÎó
* @]Parameter[=
* string $src_path Ö¸¶¨ÒªÒƶ¯µÄÔ´ÄÚÈÝ·¾¶£¬Îļþ»òĿ¼¾ù¿É
* string $dst_path Ö¸¶¨ÒªÒƶ¯µÄÄ¿±êÄÚÈÝ·¾¶£¬Îļþ»òĿ¼¾ù¿É£¬ÐÔÖÊÓÉ $src_path ¾ö¶¨£¬¿ÉΪ $src_path ϲãĿ¼
* @]Return[= boolean ´íÎó·µ»Ø FALSE£¬·ñÔò TRUE
* @]Author[= SNakeVil <51JS,BU,PHPx> (snakevil@qq.com)
* @]See[=
*/
function move($src="", $dst="", $sub=FALSE) {
if (!$src=realpath($src)) return $this->error_occur(0x000B, __FUNCTION__);
$dst = $this->generate_path($dst);
if (is_dir($src)) { // ´¦ÀíĿ¼
if (!is_readable($src)) return $this->error_occur(0x0002, $src);
if ($dst[strlen($dst)-1]!=DIRECTORY_SEPARATOR) $dst .= DIRECTORY_SEPARATOR;
if (TRUE===$sub&&$src==$this->exist_dir) return TRUE;
if (TRUE!==$sub) $this->exist_dir = "";
if (!$this->make_dir($dst)) return FALSE;
if (FALSE===$i=$this->list_dir($src)) return FALSE;
for ($j=0,$k=count($i);$j<$k;$j++) if (!$this->move($i[$j]["location"], $dst.$i[$j]["name"],TRUE)) return FALSE;
unset($i, $j, $k);
if (FALSE===strpos($this->exist_dir,$src))
if (!@rmdir($src)) return $this->error_occur(0x0004, $src); // ¶Ô·ÇÄ¿±êĿ¼µÄÉϲãĿ¼£¬É¾³ý
return TRUE;
} else {
if (!is_readable($src)) return $this->error_occur(0x0006, $src);
if ($this->verify_file($src,$dst)) return TRUE;
if (!copy($src,$dst)) return $this->error_occur(0x0007, $dst);
if (!$this->verify_file($src,$dst)) {
@unlink($dst);
return $this->error_occur(0x0007, $dst);
}
if (!@unlink($src)) return $this->error_occur(0x0006, $src); // ɾ³ýÔ´Îļþ
return TRUE;
}
}
/**
* @]Method Name[= no_comment()
* @]Purpose[=
* Çå³ýÎļþÖÐ C ¹æ·¶µÄ×¢ÊÍ
* @]Parameter[=
* string $path Ö¸¶¨ÒªÖ´ÐвÙ×÷µÄÎļþ
* @]Return[= boolean ´íÎó·µ»Ø FALSE£¬·ñÔò TRUE
* @]Author[= SNakeVil <51JS,BU,PHPx> (snakevil@qq.com)
* @]See[=
*/
function no_comment($path="") {
if (!is_file($path)) return $this->error_occur(0x000B, __FUNCTION__);
if (!is_readable($path)) return $this->error_occur(0x0006, $path);
if (!is_writeable($path)) return $this->error_occur(0x0007, $path);
if (!$th=tmpfile()) return $this->error_occur(0x000C, $path); // ´´½¨ÁÙʱÎļþ
$fh = fopen($path, "r+b");
if (!flock($fh,LOCK_EX)) { // Ëø¶¨Îļþ
fclose($fh);
unset($fh);
return $this->error_occur(0x0009, $path);
}
$fbuffer = fread($fh, $this->buffer_size*2); // Îļþ¶ÁÈ¡»º³åÇø
$tbuffer = ""; // ÁÙʱÎļþ»º³åÇø
$in_dq = $in_sq = $in_lc = $in_bc = FALSE;
while ($fblen=strlen($fbuffer)) { // ´¦ÀíÔʼÊý¾Ý
$fstats = feof($fh);
for ($i=0;$i<$fblen;$i++) { // ·ÖÎöÎļþÄÚÈÝ
if (!$fstats&&$i+5>$fblen) break; // ÎļþδÍêÈ«¶ÁȡʱÁÙ½ü»º³åÇø¶ÁÈ¡Íê³É¶ÁÈ¡ÏÂÒ»¿éÎļþÄÚÈÝ
$j = substr($fbuffer, $i, 2);
$k = $j[0];
if ($j=="/*"&&!$in_dq&&!$in_sq&&!$in_lc) { // ²»ÔÚ×Ö·û´®ºÍÐÐ×¢ÊÍÖУ¬¿é×¢ÊÍ¿ªÊ¼
$in_bc = TRUE;
$i++;
} elseif ($j=="*/"&&$in_bc) { // ¿é×¢ÊͽáÊø
$in_bc = FALSE;
$i+=2;
} elseif ($j=="//"&&!$in_dq&&!$in_sq&&!$in_bc) { // ÐÐ×¢ÊÍ¿ªÊ¼
$in_lc = TRUE;
$i++;
} elseif ($in_lc&&($k==" "||$k==" ")) $in_lc = FALSE; // ÐÐ×¢ÊͽáÊø
elseif ($j=="\\"||$j=="\""||$j=="\") { // תÒå×Ö·û
$tbuffer .= $j;
$i++;
continue;
} elseif ($k=="""&&!$in_sq&&!$in_bc&&!$in_lc) $in_dq = !$in_dq; // Ë«ÒýºÅ×Ö·û´®¿ªÊ¼¡¢½áÊø
elseif ($k==""&&!$in_dq&&!$in_bc&&!$in_lc) $in_sq = !$in_sq; // µ¥ÒýºÅ×Ö·û´®¿ªÊ¼¡¢½áÊø
if ($in_lc||$in_bc) continue; // ÔÚ×¢ÊÍÖУ¬Ìø¹ý
$tbuffer .= $fbuffer[$i];
}
$fbuffer = substr($fbuffer, $i); // Åׯú¶ÁÈ¡¹ýµÄ²¿·Ö
unset($i, $j, $k);
if (!$fstats) $fbuffer .= fread($fh, $this->buffer_size);
if ($fstats||strlen($tbuffer)>=$this->buffer_size) { // дÈëºÏ·¨Êý¾Ýµ½ÁÙʱÎļþ
if (!fwrite($th,$tbuffer)) { // дÈëʧ°Ü£¬¿Õ¼ä²»×ã
fclose($th);
flock($fh, LOCK_UN);
fclose($fh);
unset($th, $fh, $in_dq, $in_sq, $in_lc, $in_bc, $i, $j, $k);
return $this->error_occur(0x000D, "");
}
$tbuffer = "";
}
}
unset($fbuffer, $tbuffer, $fstats, $in_dq, $in_sq, $in_lc, $in_bc);
rewind($fh); // »ØÒÆÎļþÖ¸Õëµ½ÎļþÊ×
rewind($th);
$i = $j = "";
$k = 0;
while (!feof($th)) { // ½«ÁÙʱÎļþÊý¾Ýд»ØÔ´Îļþ
$i = fgets($th, $this->buffer_size);
if ($j=="") { // »ñµÃÎļþϵͳµÄ»»Ðзû
$j= substr($i, -2);
if ($j==" ") $k = 2;
elseif ($j[1]==" "||$j[1]==" ") {
$k = 1;
$j = $j[1];
} else $j = "";
}
if (substr($i, -$k)==$j) {
$i = rtrim(substr($i, 0, -$k), " ");
if (strlen($i)) fwrite($fh, $i.$j); // Çå³ýÓÒ·½¿Õ¸ñ
else continue;
} else fwrite($fh, rtrim($i, " "));
}
fflush($fh); // ±£´æ¡¢¹Ø±ÕÎļþ
ftruncate($fh, ftell($fh));
fclose($th);
flock($fh, LOCK_UN);
fclose($fh);
unset($i, $j, $k, $fh, $th);
return TRUE;
}
}
/**
* @]Error List[=
* 0x0001 Ö¸¶¨Ä¿Â¼²»´æÔÚ
* 0x0002 Ö¸¶¨Ä¿Â¼ÎÞ¶ÁȡȨÏÞ
* 0x0003 Ö¸¶¨Ä¿Â¼ÎÞдÈëȨÏÞ
* 0x0004 Ö¸¶¨Ä¿Â¼ÎÞɾ³ýȨÏÞ
* 0x0005 Ö¸¶¨Îļþ²»´æÔÚ
* 0x0006 Ö¸¶¨ÎļþÎÞ¶ÁȡȨÏÞ
* 0x0007 Ö¸¶¨ÎļþÎÞдÈëȨÏÞ
* 0x0008 Ö¸¶¨ÎļþÎÞɾ³ýȨÏÞ
* 0x0009 Ö¸¶¨ÎļþÎÞ·¨Ëø¶¨
* 0x000A Ö¸¶¨¶ÔÏó²»´æÔÚ
* 0x000B ·½·¨Ö¸¶¨²ÎÊý²»ÕýÈ·
* 0x000C ÎÞ·¨´´½¨ÁÙʱÎļþ
* 0x000D ´ÅÅ̿ռ䲻×ã
* 0x000E
* 0x000F
* 0x0010
* 0x0011
*
*/
?>
sky 58.62.103.* 2007-10-21 16:32:30