A Directory Class

Source: Internet
Author: User
Tags array count return split win32
?
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

?>

?
Table of Contents dialog box
Class OpenFileDialog extends FileDirectory {
var $filter = Array ("*.*");
function Execute ($path, $statpath) {
if ($path!= "") {
ChDir ($statpath);
$this->path = $statpath;
$ar = $this->array_dir ($path);
}else
$ar = $this->array_dir (".");
Array_multisort ($ar);
echo "
<style>
td{font-size:9pt;}
select{font-size:9pt;}
#box {border:3px outset #ffffff}
</style>
<form action= ";
echo $GLOBALS [php_self];
echo "method=post>
<table bgcolor= #cccccc cellspacing=0 cellpadding=0>
<tr><td>
<table border=0 id=box>
<tr><td>
";
echo "Current path". $this->path. " <br>\n ";
echo "<input Type=hidden name=statpath value=\" ". $this->path." \ ">\n";

echo "<select name=dirlist size=6 style=\" width:100px\ "onchange=\" this.form.submit () \ ">\n";
for ($i =0; $i <count ($ar); $i + +)
if ($ar [$i][type] = = "dir")
if ($ar [$i][name] = = ".")
echo "<option selected>". $ar [$i][name]. " \ n ";
Else
echo "<option>" $ar [$i][name]. " \ n ";
echo "</select> \ n";
echo "<select size=6 style=\" width:100px\ ">\n";
for ($i =0; $i <count ($ar); $i + +)
if ($ar [$i][type] = = "File")
echo "<option>" $ar [$i][name]. " \ n ";
echo "
</select>
</td></tr>
</table>
</td></tr>
</table>
</form>
";
}
}//openfiledialog
?>

?
Test

$dir = new OpenFileDialog ();
echo "Server Type". $dir->servermode. " <br> ";
echo "Server path". $dir->serverpath. " <br> ";
echo "Current page path". $dir->pagepath. " <br> ";
echo "Current path". $dir->path. " <br> ";
$dir->execute ($dirlist, $statpath);
?>


Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.