您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 那曲分类信息网,免费分类信息发布

php小代码----目录下读取子文件或子目录_PHP教程

2024/6/15 2:20:24发布14次查看
php小代码----目录下读取子文件或子目录 rootpath = $rootpath;
        if (is_dir($this->rootpath)) {
            $this->rootpath = pathinfo($this->rootpath, pathinfo_dirname) . directory_separator . pathinfo($this->rootpath, pathinfo_basename);
            $this->opdirectory = dir($this->rootpath);
        } else {
            $this->errormsg = '您提供的目录不存在!';
            $this->errorno = 1001;
            throw new exception($this->errormsg, $this->errorno);
        }
    }
private function read($directory, $parentpath, $modeinfo = 'mixed', $defaultdir = false, $fullpath = false) {
        $dirinfo = array();
        while (false !== ($childdirorfilename = $directory->read())) {
            switch ($modeinfo) {
                case self::recdir_mixed:
                    if ($defaultdir) {
                        $dirinfo[] = $fullpath ? $parentpath . directory_separator . $childdirorfilename : $childdirorfilename;
                    } else {
                        if ($childdirorfilename != '.' && $childdirorfilename != '..') {
                            $dirinfo[] = $fullpath ? $parentpath . directory_separator . $childdirorfilename : $childdirorfilename;
                        }
                    }
                    break;
                case self::recdir_dir:
                    if (is_dir($parentpath . directory_separator . $childdirorfilename)) {
                        if ($defaultdir) {
                            $dirinfo[] = $fullpath ? $parentpath . directory_separator . $childdirorfilename : $childdirorfilename;
                        } else {
                            if ($childdirorfilename != '.' && $childdirorfilename != '..') {
                                $dirinfo[] = $fullpath ? $parentpath . directory_separator . $childdirorfilename : $childdirorfilename;
                            }
                        }
                    }
                    break;
                case self::recdir_file:
                    if (is_file($parentpath . directory_separator . $childdirorfilename)) {
                        $dirinfo[] = $fullpath ? $parentpath . directory_separator . $childdirorfilename : $childdirorfilename;
                    }
                    break;
            }
        }
        return $dirinfo;
    }
     /**
      * (php 5 >= 5.4.0)
* 得到目录下的直接子目录或直接子文件信息
      * @param string $modeinfo[可选]
* 返回目录下信息的模式
      * mixed  返回所有的文件名及目录名
      * dir    返回所有的目录名
      * file   返回所有的文件名
      *
      * @param bool $defaultdir[可选]
* 是否包括默认的链接目录..和.
      * false  不包括
      * true   包括
      *
      * @param bool $fullpath[可选]
* 是否返回子文件或目录的路径信息
      * true  是
      * false 否
      *
* @return array 返回一个数组,记录了该目录下的信息
      */
    public function getpathdirectdirinfo($modeinfo = 'mixed', $defaultdir = false, $fullpath = false) {
        return $this->read($this->opdirectory, $this->rootpath, $modeinfo, $defaultdir, $fullpath);
    }    
}
//----------------------------test-----------------------------------------
header(content-type:text/html; charset=utf-8);
try {
    $recdir = new recdir('./calltemp/');
    $dirs = $recdir->getpathdirectdirinfo('file', true, true);
    var_dump($dirs);
} catch (exception $ex) {
    echo '在文件【' . $ex->getfile() . '】中的第' . $ex->getline() . '行报错:' . $ex->getmessage() . '(' . $ex->getcode() . ')';
}
http://www.bkjia.com/phpjc/1053347.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/1053347.htmltecharticlephp小代码----目录下读取子文件或子目录 ?php class recdir { protected $rootpath; protected $opdirectory; const recdir_mixed = mixed; const recdir_dir = dir; const recd...
那曲分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录