|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
学会了PHP,那么学其他的语言,肯定速成,反过来也一样,如果你之前学过其他的语言,那么学PHP肯定快。 <?
//目次操作基类
class FileDirectory {
var $servermode;
var $serverpath; //web办事器目次
var $pagepath; //以后页目次
var $path; //以后目次
var $ffblk; //用于存储有关文件的信息
function FileDirectory() {
set_time_limit(0); //设置网页运转工夫,0不限
$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]));
}
//获得文件信息
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;
}
//获得目次信息到数组,胜利前往时$this->path为目次的全途径
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界说停止
?>
<?
//目次对话框
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 "以后途径 ".$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
?>
<?
//测试
$dir = new OpenFileDialog();
echo "办事器类型 ".$dir->servermode."<br>";
echo "办事器途径 ".$dir->serverpath."<br>";
echo "以后页途径 ".$dir->pagepath."<br>";
echo "以后途径 ".$dir->path."<br>";
$dir->Execute($dirlist,$statpath);
?>
《PHP+MYSQL WEB开发(第三版)》号称圣经级,(也许是个不错的选择(声明:作者没给我啥好处费,我也不是书托,隔着大老远,我连他老兄的面都没见过的说-_-) |
|