Home> php教程> php手册> body text

PHP实现查找指定目录下指定的文件

WBOY
Release: 2016-06-13 10:38:56
Original
1031 people have browsed it

class document{
private $file_array
=array();
private $folder_array
=array();
private $all_array
=array();
function
search($path,$file
){
if(
is_dir($path
)){
$H=opendir($path
);
while(
false!==($_file=readdir($H
))){
if(
is_dir($path."/".$_file)&&$_file!="." && $_file!=".." && $_file!=="Thumbs.db"
){
if(
eregi($file,$path."/".$_file
)){
array_push($this->folder_array,$path."/".$_file
);
}
$this->search($path."/".$_file,$file
);
}elseif(
is_file($path."/".$_file)&&$_file!="." && $_file!=".." && $_file!=="Thumbs.db"
){
if(
eregi($file,$_file
)){
array_push($this->file_array,$path."/".$_file
);
}
}
}
$this->all_array["folder"]=$this->folder_array
;
$this->all_array["file"]=$this->file_array
;
return
$this->all_array
;
closedir($H
);
}elseif(
is_file($path
)){
if(
eregi($file,$path
)){
$this->all_array["file"]=$path
;
}
return
$this->all_array
;
}else{
return
$this->error("this folder does not exits,please check it out."
);
}
}
}
?>

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!