收藏文章 楼主
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. 川普关税政策可能导致意外后果
  2. 中美博弈2.0了?川普政府“百日执政”,撤回对华善意!
  3. 独自搭乘美国硬座火车,52小时横穿美国!
  4. 2025年,必须认识的一个英文单词 ~ tariff
  5. 台湾政府:一场误会呀
  6. 中国的中产家庭,送孩子赴美留学就是鸡肋之举?
  7. 美国《时代》周刊:DeepSeek【梁文锋】
  8. 关于“跨国婚姻”婚姻绿卡,给配偶申请绿卡的各种细节问题!
  9. 贸易战的结局已定?中美两国“各退一步”?
  10. 【读懂AI Agent】MetaGPT、Mila、斯坦福、耶鲁、谷歌的合作论文
  11. 百万民众“上街游行”抗议川普政府的百天?
  12. 美国驻华大使馆:“赴美生子”一律拒签
  13. 中国“不陪川普玩”了… 从此不理会美方闹剧!
  14. 童工可以合法夜班了?
  15. 遭遇无故吊销学签,藤校的中国留学生起诉且赢了🇺🇸国土安全部!
  16. 华人科学家再次遭遇系统性排查,75%留美学者“萌生去意”!
  17. 让人意外!股神【巴菲特】突然宣布退休
  18. BBC:在川普政府的关税打击下,为何中国不低头?
  19. 马斯克的丑闻?和多名女性有染,有上百个孩子?
  20. AI半壁江山是中国人?黄仁勋“敲警钟”:美国须觉醒!
  21. 中方意识到谈判时机已至?迅速派出“王牌代表应邀”和美国财长会面了
  22. 中美关税战的最佳写实作品~乌合麒麟发布《就不跪》
  23. 这位美国年轻人在中国玩儿一圈,浪费掉美国政府的16亿美金?
  24. 川普总统:在未来几周内开始发放“金卡签证”
  25. “240小时免签”和“离境退税”叠加组合,让美国人感受到了中国人的聪明智慧!
  26. 瞄准美国公民了?川普总统的“驱逐行动”在变本加厉
  27. 这小伙年仅25岁,已经是百亿美金公司的创始CEO了!
  28. 哪些关键技术决定了如今大模型格局?Google的首席科学家“万字演讲”回顾AI发展的十年
  29. 美国“大规模”取消国际留学生的签证
  30. 美国华人在近期出入境美国,绿卡和签证的持有者须知!
  31. 美国小伙儿在武当山修行十余年,终于获得“中国绿卡”了!
  32. 关税战持续了96小时… 突然大反攻?
  33. 美国人在凌晨三点排队,不为苹果手机… 竟然是为中国毛绒玩具“拉布布”?
  34. 在量子世界“玩儿游戏”?物理学家展示了量子计算机的新前景
  35. 近半数中国小包裹的接收人是贫困美国百姓?
  36. 盘点美国最繁华的城市 top10

美国动态 美果搜索

Your IP: 3.145.125.13, 2025-05-16 14:26:48

Processed in 0.50609 second(s)

头像

用户名:

粉丝数:

签名:

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