如何读取当前目录下的所有文件
<?$dirnow=getcwd(); //当前目录
$dirnowfile = scandir($dirnow, 1);//目录中文件
foreach ($dirnowfile as $dirfile){
echo $dirfile."</br>";
}
?>
上面是我写的,不要笑话我 :)
下面是问题:
如何能按文件夹-文件 这样的顺序排列,并且不输出.和..,然后主要是如果是目录可以点击进去,在看到里面的文件。
要求:不要用FUNCTION写,根据我上面这种思路写。因为我是初学者,这样写比较容易理解。十分感谢。想了半天也没想出来怎么能按文件夹-文件排列,还要可以点击进入下一层文件夹
$path = "."; //一般点就是当前目录吧
if(!$dir = $_GET[subdir])$dir=''; //获取提交的文件夹名
$dirs = opendir("$path/$dir"); //打开当前目录 输出文件夹
while($loopfile = readdir($dirs))
{
if(true == is_dir($dir.$loopfile) ){
printf(" Dir:<a href=\"?subdir=%s\">%s</a><br>",$loopfile,$loopfile);
}
}//end while
closedir("$path/$dir");
$dirs = opendir("$path/$dir"); //打开当前目录 输出文件
while($loopfile = readdir($dirs))
{
if(false == is_dir($dir.$loopfile) ){
printf(" File:%s<br>",$loopfile);
}
}//end while
closedir("$path/$dir");
?>
只能提供个思路,代码不完善
页:
[1]