php读取目录、文件并显示的函数_PHP教程

WBOY
Lepaskan: 2016-07-13 17:23:41
asal
1103 orang telah melayarinya

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

/*
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...
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!