我正在为lighttpd创建一个列出
PHP5脚本的目录.在给定目录中,我希望能够列出直接子目录和文件(带有信息).
快速搜索后,DirectoryIterator似乎是我的朋友:
- foreach (new DirectoryIterator('.') as $file)
- {
- echo $file->getFilename() . '<br />';
- }
怎么做(使用ArrayObject / ArrayIterator?)?
谢谢
以上解决方案对我不起作用.这是我的建议:
- class SortableDirectoryIterator implements IteratorAggregate
- {
- private $_storage;
- public function __construct($path)
- {
- $this->_storage = new ArrayObject();
- $files = new DirectoryIterator($path);
- foreach ($files as $file) {
- $this->_storage->offsetSet($file->getFilename(),$file->getFileInfo());
- }
- $this->_storage->uksort(
- function ($a,$b) {
- return strcmp($a,$b);
- }
- );
- }
- public function getIterator()
- {
- return $this->_storage->getIterator();
- }
- }