<p> 该脚本从一个指定目录中读取文件名,之后把这些文件名返回到数组中,还包括文件个数。</p><p> 源代码如下:</p><p> <code><?<br />/*<br />This script read the filenames from a specified directory and returns them in an array.<br />The number of filenames is also returned.<br />Copyleft(L) 1999 Eric Persson, eric@persson.tm, http://www.persson.tm/scripts/<br />*/<br />Function searchdir($basedir)<br />{<br />global $filelisting, $number; //defines the two variables as global so they can be accessed from outside the function<br />unset($filelisting); //kills $filelisting in case it have been used earlier in the script<br />unset($number); //same as above<br />$handle=opendir($basedir);<br />while ($file = readdir($handle)) {<br />if ($file=="." or $file=="..") {<br />}<br />else {<br />$filelisting[]="$basedir$file";<br />};<br />};<br />$number=sizeof($filelisting); //gets the size of the array<br />};<br />searchdir("./"); //runs the function to search the current directory<br />echo $filelisting[1]; //echos the second value in the array<br />echo $number; //echos the size of the array<br />?></code></p>