<?php
$path = "/var/www/abc";
$handle = opendir($path);
echo "文件:\n";
while ($file = readdir($handle))
{
    echo "$file\n";
}
closedir($handle); 
?>
就可以得到此目录下的所有文件,子目录也算文件,还有 . 和 .. 目录

解决方案 »

  1.   

    对,减去2才行。
    再给你一段代码,是http://phptv.com
    中的一段   {
    $pa1=new fileopen;
    $m="r+";
    $pa1->path="$filenumphptv";
    $pa1->open($m);
    $answerpal=new fileopen;
    $answerpal->path="$answerfilenumphptv";
    $answerpal->open($m);
    ?>
    论坛目前共有<?echo "$pa1->cread";?>篇文章&nbsp;<?echo$answerpal->cread?>篇回贴
    <?  }else{?>
    本版共有 
            <?
    $d=opendir($datapath);

    $countfile=0;
    while($countdirfile=readdir($d))
     {
    $countfile=$countfile+1;  
    }
    $countfile=$countfile-2;
    closedir($d);
    //PHP3 兼容代码
    echo $countfile;
    ?>
            篇文章 <?
    $l=opendir($answerdatapath);

    $countfile1=0;
    while($countdirfile1=readdir($l))
     {
    $countfile1=$countfile1+1;  
    }
    $countfile1=$countfile1-2;
    closedir($l);
    echo "$countfile1";echo"篇回贴";}?>
            <? 
      if(filesize($read->filename)<300)
    {
    echo "<marquee behavior=Alternate scrolldelay=80 scrollamount=3 width=250 height=12 msambientcpg=936>$atext_action</marquee><o:p></o:p>
    ";
    }elseif(filesize($read->filename)>300){
    echo "<marquee behavior=Alternate scrolldelay=80 scrollamount=3 width=250 height=12 msambientcpg=936>$atext_action1</marquee><o:p></o:p>
    ";