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

WBOY
發布: 2016-07-13 17:23:41
原創
1104 人瀏覽過

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

/*
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...
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!