收藏文章 楼主
PHP源代码集锦
网友【血蜘蛛】 2005-06-20 20:01:55 分享在【时代发展的印记】版块    1    1
代码:/********************************************
* *
* Name : File System Object *
* Author : Windy_sk *
* Time : 2003-09-12 *
* Email : [email protected] *
* HomePage: None (Maybe Soon) *
* Notice : U Can Use & Modify it freely, *
* BUT PLEASE HOLD THIS ITEM. *
* *
********************************************/

class FileSystemObject {
var $main_dir = "./";
Var $dir_map = "";
var $search = array();

function FileSystemObject($main_dir = "./") {
$this->main_dir = $main_dir;
return;
}

function Get_Attrib($file_att){
if(strlen($file_att)!=3) return "Error";
$att_list = array("---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx");
$the_attrib = "";
for($i=0; $i<3; $i++) {
$this_char=(int)substr($file_att,$i,1);
if($this_char > 7 || $this_char < 0) return "Error";
$the_attrib .= $att_list[$this_char];
}
return $the_attrib;
}

function Get_Size($file_size) {
if($file_size < 1024){
$file_size = (string)$file_size . " Bytes";
}else if($file_size < (1024 * 1024)){
$file_size = number_format((double)($file_size / 1024), 1) . " KB";
}else if($fil_esize < (1024 * 1024 * 1024)){
$file_size = number_format((double)($file_size / (1024 * 1024)), 1) . " MB";
}else{
$file_size = number_format((double)($file_size / (1024 * 1024 * 1024)), 1) . " GB";
}
return $file_size;
}

function Judge_Child($dir = "", $only_dir = true){
if(empty($dir)) $dir = $this->main_dir;
$mydir = @dir($dir);
if(!$mydir) return false;
while($file = $mydir->read()){
if($file!="." && $file!=".."){
if($only_dir) {
if(is_dir($dir."/".$file)) return true;
} else {
return true;
}
}
}
$mydir->close();
return false;
}

function MultiDel($dir){
if(empty($dir)) return;
if(is_dir($dir)){
$mydir = opendir($dir);
while($file = readdir($mydir)) {
if($file!="." && $file!="..") {
$the_name = $dir."/".$file;
is_dir($the_name) ? $this->MultiDel($the_name) : unlink($the_name);
}
}
closedir($mydir);
rmdir($dir);
}else{
unlink($dir);
}
return;
}

function Make_Dir($dir) {
if(is_dir($dir)) {
print("Directory {$dir} already exist !");
} else {
@mkdir($dir,0777) or print("Operation Failed in Creating Directory {$dir} ,Please Check Your Power!");
}
return;
}

function Rename_File($file, $newname) {
if(file_exists($file)) {
if(file_exists($newname)) {
print("File {$newname} already exist !");
} else {
@rename($file, $newname) or print("Operation Failed in Renaming {$file} ,Please Check Your Power!");
}
} else {
print("Cannot Find File {$file} !");
}
return;
}

function Move_File($file, $dir) {
if(is_dir($dir))
$this->Rename_File($file, str_replace("//","/",$dir."/".basename($file)));
else
print("Cannot Find Directory {$dir} !");
return;
}

function Get_File($file) {
return is_file($file)?join("",file($file)):"";
}

function Write_File($file, $content) {
if(file_exists($file)) $this->Set_Attrib($file, 0777);
$fp=@fopen($file,"w");
if($fp) {
flock($fp,2);
fputs($fp,$content);
fclose($fp);
} else {
print("Cannot Create File {$file} !");
}
return;
}

function Set_Attrib($file, $attrib) {
if(file_exists($file)) {
@chmod($file, $attrib) or print("Operation Failed in Setting Attrib of {$file} , Please Check Your Power!");
} else {
print("Cannot Find File {$file} !");
}
return;
}

function Search_File($keyword, $inc_word, $deep, $dir) {
$mydir = @dir($dir);
if(!$mydir) return false;
while($file = $mydir->read()) {
$the_name = str_replace("//","/",$dir."/".$file);
if(is_dir($the_name)) {
if($deep && $file!="." && $file!=".."){
$this->Search_File($keyword, $inc_word, $deep, $the_name);
}
} else {
if(@strpos(basename($the_name), $keyword)!==false || empty($keyword)) {
if(!empty($inc_word)) {
if($this->Search_File_Content($the_name, $inc_word)) array_push($this->search, $the_name);
} else {
array_push($this->search, $the_name);
}
}
}
}
$mydir->close();
return;
}

function Search_File_Content($file, $inc_word) {
return (strpos($this->Get_File($file), $inc_word) !== false);
}

function Search($keyword="", $inc_word="", $deep=false, $dir="") {
if(empty($dir)) $dir = $this->main_dir;
$this->search = array();
$this->Search_File($keyword, $inc_word, $deep, $dir);
return $this->search;
}

function Get_Tree($dir = "", $filetype = ""){
if(empty($dir)) $dir = $this->main_dir;
$mydir = @dir($dir);
if(!$mydir) return false;
$file_list = array("dir" => array(), "file" => array(), "custom" => array());
while($file = @$mydir->read()){
if(!$file) continue;
if($file!="." && $file!=".."){
$string = str_replace("//","/",$dir."/".$file);
if(is_dir($string)){
$file_list["dir"][] = $string;
}else{
$file_list["file"][] = $string;
if(!empty($filetype)) {
$ext = str_replace(".", "", strrchr($string ,"."));
if(strpos($filetype, $ext)!==false)
$file_list["custom"][] = $string;
}
}
}
}
$mydir->close();
sort($file_list["dir"]);
sort($file_list["file"]);
sort($file_list["custom"]);
return $file_list;
}

function Make_DirMap($dir = "", $simple, $loop) {
if(empty($dir)) $dir = $this->main_dir;
if(!is_dir($dir)) return;
$file_list = $this->Get_Tree($dir);
for($i=0; $i$the_name = $file_list["dir"][$i];
$the_name = str_replace("&", "&", $the_name);
$this->dir_map .= "Get_Attrib(substr(DecOct(fileperms($the_name)),-3))."\" Time=\"".date("m/d/y H:i:s", filemtime($the_name))."\"")."> ";
if($loop) $this->Make_DirMap($the_name, $simple, $loop);
$this->dir_map .= "
";
}
for($i=0; $i$the_name = $file_list["file"][$i];
$the_name = str_replace("&", "&", $the_name);
$this->dir_map .= "Get_Size(filesize($the_name))."\" Attrib=\"".$this->Get_Attrib(substr(DecOct(fileperms($the_name)),-3))."\" Time=\"".date("m/d/y H:i:s", filemtime($the_name))."\"")." /> ";
}
unset($file_list);
return;
}

function Get_DirMap($declaration = false, $simple = false, $loop = true){
$this->dir_map = $declaration?" ":"";
$this->dir_map .= "main_dir}\" Data=\"".date("m/d/y H:i:s", time())."\"> ";
$this->Make_DirMap($this->main_dir, $simple, $loop);
$this->dir_map .= "
";
return $this->dir_map;
}
}
?>
meiguo.com 发布人签名/座右铭·有时你看似是一件很吃亏的事,往往会变成非常有得的事。
·凡事都留有余地,因为人是人,不是神,不免有错处,可以原谅人的地方,就原谅人。
·好的时候不要看得太好,坏的时候不要看的太坏。
大家都在看
回复/评论列表
默认   热门   正序   倒序
meiguo.com 创始人

emotion

1   2005-06-20 20:01:55  回复

回复/评论:PHP源代码集锦

暂无用户组 升级
退出
等级:0级
美果:
美过
精华推荐
  1. 毅力号火星车揭示了杰泽罗陨石坑的水活动历史
  2. 在美国生活半年,真实观察了文化差异!
  3. 联邦法院驳回了川普政府的“出生公民权”行政令
  4. 美国签证新规:申请人须回母国面谈
  5. Zillow和Redfin“摊上大事儿”!五大州的总检察长起诉了房产平台合谋做局
  6. 美国众议院通过了巨额军费预算,马斯克警示财政风险!
  7. 三只小猪都知道砖头房子更好,为何美国房子是木头房?
  8. TikTok美国业务的“合规运营”方案细节披露
  9. 美国的七大都会区“房市调头”,买方作主了!
  10. 母亲给大一女儿恋爱八项要求
  11. 川普政策变动,竟然催生了智利的生育旅游热潮?
  12. 中美元首长“电话粥”,聚焦经贸和TikTok合作!
  13. 福建舰“电磁弹射系统技术”获全球关注
  14. 最高法院裁定:支持川普政府的移民执法政策
  15. iPhone 17系列新品、iPhone Air发布了!
  16. 佛罗里达的一名中学生在AI提问,然后被捕了!
  17. 美国“风行者”超大运输机计划曝光
  18. 马斯克成为全球首位身家5000亿美元的富豪
  19. 骨胶水的研发获突破,临床试验显示了安全有效!
  20. 李开复:如果老板不AI,公司将会被AI淘汰!
  21. 联合国大会“史上最尴尬”一幕:他上台后,观众纷纷撤离!
  22. 中国AI芯片产业迎来了技术突破和生态崛起
  23. 川普总统签署了备忘录,贩毒集团成为“国家之敌”!
  24. 美股市值突破“全球GDP半数”大关
  25. 川普总统在联合国演讲,声称中国不愿用风力发电?
  26. 启程回国:美元很香,但回家的路更香!
  27. 美国签证新规“取消第三国面签”的选项了
  28. 中美两国在马德里谈判,聚焦TikTok和关税问题!
  29. 马斯克的净资产创纪录,突破5000亿美元!
  30. 川普政府打算发放两千美元的关税补贴
  31. 大学排名更新:顶尖学府稳固,新兴学校快速上升
  32. 美国市场的智能手机“印度制造”的份额激增
  33. 美国宣传制裁东南亚的19个电信诈骗网络实体
  34. 在美国买房半年后,总结了两个扎心感受!
  35. 川普总统的“科技巨头宴”收获千亿级的投资承诺
  36. 我的人生有三个账户!伊隆·马斯克在斯坦福大学的最新演讲

美国动态 美果搜索

Your IP: 216.73.216.27, 2025-10-13 08:43:26

Processed in 0.22855 second(s)

头像

用户名:

粉丝数:

签名:

资料 关注 好友 消息
已有0次打赏
(1) 分享
分享
取消