问题描述
我有一个PHP脚本读取目录,并列出链接形式的所有文件/目录和它的作品,但我试图得到它是递归的,这样,当我选择另一个目录它再次使用脚本里面显示的文件。现在,当我选择一个目录,它只是转到默认的Apache上市....任何帮助AP preciated。
脚本:
< PHP
$目录名称='/硬盘/存储/ AppsOSs /';
$ webdirname ='/ AppsOSs'; //什么目录显示为但从浏览器的角度$ DIR =执行opendir($目录名);
$ file_list中='';而(($文件= READDIR($ DIR))!= FALSE){
如果(($文件=)及!'。';&安培;!($文件='..')){
$ file_list中=&下; A HREF = \\$ webdirname / $文件\\> $文件&下; / A>&所述峰; br />中;
}
}closedir($目录);
?>&所述p为H.;
< = $ file_list中&GT?;
&所述; / P>
在目录迭代和递归迭代看看
甚至递归迭代目录
I have a php script that reads a directory and lists all the files/directories in link form, and it works, except I'm trying to get it to be recursive so that when I choose another directory it once again uses the script to display the files inside. Right now when I select a directory it just goes to the default apache listing....any help is appreciated.
Script:
<?php
$dirname = '/drives/Storage/AppsOSs/';
$webdirname = '/AppsOSs'; // what the directory appears as from the web browser's point of view
$dir = opendir($dirname);
$file_list = '';
while(($file = readdir($dir)) != false) {
if(($file != '.') && ($file != '..')) {
$file_list .= "<a href=\"$webdirname/$file\">$file</a><br/>";
}
}
closedir($dir);
?>
<p>
<?=$file_list?>
</p>
Take a look at the Directory Iterator and the Recursive Iterator
http://php.net/manual/en/class.directoryiterator.php
or even the Recursive Directory Iterator
http://www.php.net/manual/en/class.recursivedirectoryiterator.php
这篇关于用PHP脚本列出目录帮助需要递归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!