PHP function to read directories and files and display them_PHP tutorial

WBOY
Release: 2016-07-13 17:23:41
Original
1123 people have browsed it

读取指定的目录,并显示其中的文件个数和文件名。

/*
This script read the filenames from a specified directory and returns them in an array.

*/
Function searchdir($basedir)
{
global $filelisting, $number; //defines the two variables as global so they can be accessed
unset($filelisting); //kills $filelisting in case it have been used earlier in the
unset($number); //same as above
$handle=opendir($basedir);
while ($file = readdir($handle)) {
if ($file=="." or $file=="..") {
} else {
$filelisting[]="$basedir$file";
};
};
$number=sizeof($filelisting); //取得文件个数
};
searchdir("."); //runs the function to search the current directory
echo $filelisting[1]; //echos the second value in the array
echo $number; //echos the size of the array
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/532221.htmlTechArticle读取指定的目录,并显示其中的文件个数和文件名。 /* This script read the filenames from a specified directory and returns them in an array. */ Function searchd...
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 Tutorials
More>
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!