• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

一个目录类_php

php 搞代码 7年前 (2018-06-19) 158次浏览 已收录 0个评论

<?
//目录操作基类
class FileDirectory {
  var $servermode;
  var $serverpath;    //web服务器目录
  var $pagepath;    //当前页目录

http://www.gaodaima.com/45553.html一个目录类_php

  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,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:一个目录类_php

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址