php 自定义类 Clscandir
class Clscandir { public $path; public $sorting_order; public $completeFiles ; public $completeDirs ; public $files; public $dirs ; public $filesDirs ; public $completeFilesDirs ; public function __construct($path,$sorting_order=0){ $this->scandir($path , $sorting_order); $this->get_complete_filesDirs(); $this->get_complete_dirs(); return $this->filesDirs; } public function scandir($path,$sorting_order=0){ $this->path = $path ; $this->sorting_order = $sorting_order; $this->filesDirs=scandir ( $path , $sorting_order ) ; return $this->filesDirs; //sort()升序 rsort()降序 ; } public function get_complete_filesDirs(){ if(count($this->completeFilesDirs)==0){ foreach($this->filesDirs as $k => $v ){ $this->completeFilesDirs[] = $this->_format_name($this->path."/".$v); } } return $this->completeFilesDirs; } public function get_complete_dirs(){ if(count($this->completeDirs)==0){ foreach($this->completeFilesDirs as $k=>$v){ if(is_dir($v)){ $this->completeDirs[]=$v; }else{ $this->completeFiles[]=$v; } } } return $this->completeDirs; } public function get_complete_files(){ return $this->completeFiles; } private function iva(){} protected function ote(){} public function _scandir($path){ $dir = dir($path); $retarr = array( ) ; while (($file = $dir->read()) !== false) { $retarr[] = ($file) ; } $dir->close(); $retarr["cwd"]=$this->_format_name(getcwd()); return $retarr; } public function _format_name($str){ return preg_replace ( ‘/\/{1,}/‘ , ‘/‘ , str_replace ( ‘\\‘ , ‘/‘ , $str ) ) ; } public function show(){ echo "目录:<br>"; secho($this->completeDirs); echo "文件:<br>"; secho($this->completeFiles); } public function demo(){ echo str_replace(array("\n"," "),array("<br>"," "), htmlspecialchars(‘ $dir=_default_em($_REQUEST["dir"],\"I:/AppServ/www/_doll/"); $scandir=new CLsandir($dir,0); secho($scandir->get_complete_dirs()); secho($scandir->get_complete_files());‘) ) ; } public function each($arr,$callback=""){ if(!is_array($arr))return ‘Is not array!‘; $retarr=array(); foreach($arr as $k=>$v){ if(""!=$callback) {$retarr[$k]=$callback($v); } else {$retarr[$k]=$v;} } return $retarr; } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。