作者:windy2000 时间: 2003-10-06 文档类型:原创 来自:蓝色理想
第 1 页 PHP源代码集锦-File System Object 第 2 页 PHP源代码集锦-Some Function 第 3 页 PHP源代码集锦-MySQL Manager 第 4 页 PHP源代码集锦-Html Transfer Code
File System Object:<?php /******************************************** * * * Name : File System Object * * Author : Windy_sk * * Time : 2003-09-12 * * Email : flyhorses@sina.com * * 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<count($file_list["dir"]); $i++) { $the_name = $file_list["dir"][$i]; $the_name = str_replace("&", "&", $the_name); $this->dir_map .= "<Directory Name=\"".basename($the_name)."\"".($simple?"":" Attrib=\"".$this->Get_Attrib(substr(DecOct(fileperms($the_name)),-3))."\" Time=\"".date("m/d/y H:i:s", filemtime($the_name))."\"").">\n"; if($loop) $this->Make_DirMap($the_name, $simple, $loop); $this->dir_map .= "</Directory>\n"; } for($i=0; $i<count($file_list["file"]); $i++) { $the_name = $file_list["file"][$i]; $the_name = str_replace("&", "&", $the_name); $this->dir_map .= "<File Name=\"".basename($the_name)."\"".($simple?"":" Size=\"".$this->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))."\"")." />\n"; } unset($file_list); return; } function Get_DirMap($declaration = false, $simple = false, $loop = true){ $this->dir_map = $declaration?"<?xml version=\"1.0\" encoding=\"gb2312\" standalone=\"yes\"?>\n":""; $this->dir_map .= "<DirectoryMap Root=\"{$this->main_dir}\" Data=\"".date("m/d/y H:i:s", time())."\">\n"; $this->Make_DirMap($this->main_dir, $simple, $loop); $this->dir_map .= "</DirectoryMap>"; return $this->dir_map; } } ?>[Ctrl+A 全部选择 然后拷贝]
出处:蓝色理想 责任编辑:cjj
上一页 下一页 PHP源代码集锦-Some Function
◎进入论坛网络编程版块参加讨论
蓝色理想版权申明:除部分特别声明不要转载,或者授权我站独家播发的文章外,大家可以自由转载我站点的原创文章,但原作者和来自我站的链接必须保留(非我站原创的,按照原来自一节,自行链接)。文章版权归我站和作者共有。
转载要求:转载之图片、文件,链接请不要盗链到本站,且不准打上各自站点的水印,亦不能抹去我站点水印。
特别注意:本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有,文章若有侵犯作者版权,请与我们联系,我们将立即删除修改。