PHP Small Code----directory to read sub-files or subdirectories
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 = ' The directory you provided does not exist! '; $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 ($defau Ltdir) {$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)
* Get direct sub-directories or direct sub-file information under directory * @param string $modeInfo [optional]
* Returns the mode of the information in the directory * mixed returns all filenames and directory names * dir returns all directory names * file returns all filenames *
* @param bool $defaultDir [OPTIONAL]
* Whether to include the default link directory: and. * False not including * true includes *
* @param bool $fullPath [OPTIONAL]
* Whether to return path information for child files or directories * True is * false no *
* @return Array returns an array that records the information in this directory */Public function getpathdirectdirinfo ($modeInfo = ' mixed ', $defaultDir = False, $f Ullpath = 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 ' in file '. $ex->getfile (). "The first of the". $ex->getline (). ' Line error: '. $ex->getmessage (). ' ('. $ex->getcode (). ')';}
http://www.bkjia.com/PHPjc/1053347.html www.bkjia.com true http://www.bkjia.com/PHPjc/1053347.html techarticle PHP Small Code----Directory read sub-files or subdirectories? PHP class RecDir {protected $rootPath; protected $opDirectory; const recdir_mixed = MIXED; co NST recdir_dir = DIR; Const RECD ...