收藏文章 楼主
PHP源代码集锦
网友【血蜘蛛】 2005-06-20 20:42:36 分享在【时代发展的印记】版块    2    1
File System Object:

代码:/********************************************
* *
* 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 发布人签名/座右铭·有时你看似是一件很吃亏的事,往往会变成非常有得的事。
·凡事都留有余地,因为人是人,不是神,不免有错处,可以原谅人的地方,就原谅人。
·好的时候不要看得太好,坏的时候不要看的太坏。
大家都在看
回复/评论列表
默认   热门   正序   倒序
蝶舞门人
2F
太强,不能不顶----
 0   2005-09-15 10:13:56  回复
meiguo.com 创始人

emotion

1   2005-06-20 20:42:36  回复

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

暂无用户组 升级
退出
等级:0级
美果:
美过
精华推荐
  1. YouTube“反诈频道”助力警方,破获6500万美元诈骗案!
  2. 麦当劳CEO声称美国品牌的声誉在全球下滑
  3. SpaceX的星舰“第十次试飞”成功了
  4. 从近期的中国留学生在美国入境的悲惨遭遇说起
  5. 美国签证新规“取消第三国面签”的选项了
  6. 不输常春藤!盘点学费低、薪资高的25所美国公立大学
  7. 敌友即友?马斯克和扎克伯格开始接触,图谋合伙收购OpenAI?
  8. 美国市场的智能手机“印度制造”的份额激增
  9. 持中国大陆护照在申请美国签证的注意事项更新(2025年8月版本)
  10. 植物油更健康?动物油脂摄入或将加速肿瘤生长
  11. 川普家族竟然靠它狂揽45亿美金!操盘手是赵长鹏?
  12. 启程回国:美元很香,但回家的路更香!
  13. iPhone 17系列新品、iPhone Air发布了!
  14. 中国留学生在入境美国时遭遇驱逐,禁止五年内再入境!
  15. Niche发布2026全美最佳大学榜单 MIT重回榜首
  16. 选择西雅图、圣地亚哥还是洛杉矶?全面对比“三城生活”
  17. 相差3米!星舰试飞“精准溅落”展现技术突破
  18. 华人留学生“索赔1亿美元控诉”大学期间的农药伤害
  19. 中国留学生在入境美国时遭遇盘查,中方大使馆发布安全提醒!
  20. 美国宣传制裁东南亚的19个电信诈骗网络实体
  21. 华人科学家身陷“杀猪盘”,短短数月就被掏光250万美元积蓄!
  22. 加州州长竟然模仿川普总统的风格发帖,粉丝数和支持率“都涨了”!
  23. 马斯克“xAI”起诉前工程师“泄露机密”
  24. 川普总统的“科技巨头宴”收获千亿级的投资承诺
  25. 李开复:如果老板不AI,公司将会被AI淘汰!
  26. 美国华裔二代坦言:中国发展现状,让父辈移民后悔了!
  27. 2025年度的美国公立高中排名发布,咱只关注前三!
  28. 美国“真放宽”了对中国留学生的入境政策?
  29. 美国年轻人的“中国观”悄然转变
  30. 休斯顿机场“小黑屋内的铝箔纸”:中国留学生遭遇遣返的36小时煎熬
  31. 从美国回到中国的,基本都会被问及这些问题!
  32. 川普总统的态度突变,暗示乌克兰应该反击俄罗斯本土?
  33. 先交押金!美国重启了“签证保证金”试点计划
  34. ICE抓捕的非法移民中,中国人数量激增?
  35. 白宫开通了TikTok 账号,传播政策信息!
  36. 全美房地产市场在趋向中性,区域分化明显!

美国动态 美果搜索

Your IP: 216.73.216.36, 2025-09-18 10:17:03

Processed in 1.59853 second(s)

头像

用户名:

粉丝数:

签名:

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