?
Catalog Operations Base Class
Class FileDirectory {
var $servermode;
var $serverpath; Web server directory
var $pagepath; Current Page Catalog
var $path; Current directory
var $ffblk; Used to store information about a file
function FileDirectory () {
Set_time_limit (0); Set web run time, 0 unlimited
$this->serverpath = $GLOBALS [Document_root]. " /";
$this->path = $this->pagepath = dirname (Eregi_replace ("//", "/", $GLOBALS [Script_filename]). " /";
if (eregi ("Win32", getenv ("Server_software"))
$this->servermode = "WIN32";
}
function First_dir () {
Return DirName (Eregi_replace ("//", "/", $GLOBALS [Script_filename]));
}
Get file information
function File_info ($filename) {
$ar [name] = $filename;
$ar [Type] = filetype ($filename);
$ar [Read] = is_readable ($filename);
$ar [Write] = is_writeable ($filename);
$ar [EXEC] = is_executable ($filename);
$ar [TIME] = Date ("y-m-d h:i:s", Filemtime ($filename));
$ar [Size] = FileSize ($filename);
$ar [Style] = ($ar [type]== "dir"?] D ":"-")
. ($ar [read]? " R ":"-")
. ($ar [write]? W ":"-")
. ($ar [exec]? " X ":"-");
return $ar;
}
function Format_path ($path) {
$tar = Split ("/", $path);
$sar = Split ("/", $this->path);
$t = count ($tar);
$s = count ($sar);
if ($tar [$t-1] = = "") $t-;
if ($sar [$s-1] = = "") $s-;
$j = 0;
while ($tar [$j] = = "...") {
$j + +;
$s--;
}
$p = "";
for ($i =0; $i < $s; $i + +)
$p. = $sar [$i]. " /";
for ($i = $j; $i < $t; $i + +)
if ($tar [$i]!= ".")
$p. = $tar [$i]. " /";
$this->path = $p;
}
Gets the directory information to the array, $this->path as the full path to the directory when successfully returned
function Array_dir ($pathname = ".") {
$old = $this->path;
if ($this->servermode = = "WIN32")
$path = Str_replace ("\", "/", $pathname);
Else
$path = $pathname;
$this->format_path ($path);
if (! ($handle = @opendir ($path))) {
$path = DirName ($pathname);
$handle = Opendir ($path);
}
if (@chdir ($this->path)) {
while ($file = Readdir ($handle)) {
$ar [] = $this->file_info ($file);
}
}else
$this->path = $old;
Closedir ($handle);
return $ar;
}
}//filedirectory definition End
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.