php读取目录、文件并显示的函数
时间:2007-02-17 来源:PHP爱好者
读取指定的目录,并显示其中的文件个数和文件名。
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
<?
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
/*
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
This script read the filenames from a specified directory and returns them in an array.
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
*/
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
Function searchdir($basedir)
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
{
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
global $filelisting, $number; //defines the two variables as global so they can be accessed
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
unset($filelisting); //kills $filelisting in case it have been used earlier in the
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
unset($number); //same as above
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
$handle=opendir($basedir);
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
while ($file = readdir($handle)) {
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
if ($file=="." or $file=="..") {
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
} else {
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
$filelisting[]="$basedir$file";
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
};
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
};
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
$number=sizeof($filelisting); //取得文件个数
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
};
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
searchdir("."); //runs the function to search the current directory
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
echo $filelisting[1]; //echos the second value in the array
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
echo $number; //echos the size of the array
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
?>
php爱好者站 http://www.phpfans.net 为phper提供一切资讯.
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
<?
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
/*
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
This script read the filenames from a specified directory and returns them in an array.
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
*/
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
Function searchdir($basedir)
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
{
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
global $filelisting, $number; //defines the two variables as global so they can be accessed
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
unset($filelisting); //kills $filelisting in case it have been used earlier in the
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
unset($number); //same as above
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
$handle=opendir($basedir);
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
while ($file = readdir($handle)) {
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
if ($file=="." or $file=="..") {
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
} else {
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
$filelisting[]="$basedir$file";
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
};
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
};
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
$number=sizeof($filelisting); //取得文件个数
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
};
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
searchdir("."); //runs the function to search the current directory
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
echo $filelisting[1]; //echos the second value in the array
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
echo $number; //echos the size of the array
wwww.chin aitpower.comPRFnEsWfrcmetpQ5at7eMWVso
?>
php爱好者站 http://www.phpfans.net 为phper提供一切资讯.
相关阅读 更多 +