收藏文章 楼主
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. 美国“H1B签证”新一轮抽签在3月份开启,新变化真不少!
  3. 川普总统在接任首日或将推上百项行政命令
  4. 滞留美国的华裔非法移民“遭遇流放”,首批119人已起飞!
  5. 美签面签后的全面复盘:审核原因和拒签因素剖析
  6. 美军再次增建两艘新航母
  7. DOGE让1.4万公务员失业?马斯克已经做好最坏心理准备!
  8. 赴美生子的中国人在纠结剖不剖?美国人在寻思“移民鹤岗”呢!
  9. 在美国买房,看Open House时需要注意的问题汇总
  10. 周受资 ~ 真正强大的CEO
  11. DeepSeek已经让成人玩具“率先受益”
  12. TikTok在美国全面恢复了
  13. 川普总统首次公开回应“TRUMP”数字货币项目
  14. 23岁中国女留学生在南加州的住所内遇害,曾控诉白人男友“性虐待”!
  15. 《纽约时报》刊登的中国父子文章:为何送儿子留学美国
  16. 福布斯曝光了Deepseek 梁文锋的净资产
  17. 遭遇“断粮”的BBC叛变了?
  18. 赵本山在纽约:前排票价1400美元,团队聚餐画面曝光!
  19. 美国首都机场为何全美风险最高?川普总统“怒喷航管弱智”
  20. “复活版”TikTok“拿捏了”美国人的软肋?
  21. 风向有变?🇨🇳中央召开民企座谈会,寓意深刻!
  22. 在美国生活,这四证缺一不可!
  23. 陆地入境美国受阻,“华人偷渡客”已经改用快艇登陆了?
  24. 滞留太空的NASA宇航员即将返回地球
  25. 中国电影市场的2025春节档 ~ 简直就是神仙打架
  26. 川普政府的“朝令夕改”最短纪录再次刷新
  27. 大S【徐熙媛】病逝,享年48岁!
  28. 北美留学生注意,美国和加拿大即将共享所有移民和签证讯息!
  29. 川普总统正式接任,成为美国第47任总统
  30. 谷歌地图和苹果地图已经都修改了美国湾(墨西哥湾)
  31. “TikTok难民”如何玩转中国社交网络?一夜间“小红书”刷屏全美
  32. 全美境内,非法移民“驱逐战”打响了!
  33. 华人害华人!涉及1500万美元的芝加哥“大型持枪绑架案”嫌疑人半数落网
  34. 以色列和哈马斯终于同意停火
  35. 美国房产的保值要点,但却被九成华人买家忽视了!
  36. 川普总统在开工首日就向1300万非法移民动手了

美国动态 美果转盘 美果商店

Your IP: 18.224.62.229, 2025-03-16 07:57:51

Processed in 0.66678 second(s)

头像

用户名:

粉丝数:

签名:

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