Tôi đang cố gắng để có được một danh sách với thư mục và thư mục con tôi có những điều sau đây cho phép tôi để có được các thư mục và thư mục phụ nhưng tôi cần nó được sắp xếp như ví dụ như dưới đây tôi đã cố gắng nhưng tôi không biết làm thế nào tôi sẽ có được xung quanh.Làm thế nào để hiển thị các thư mục và thư mục con từ thư mục trong PHP
Root/
Root/Images
Root/Images/UserImages
Root/Text/
Root/Text/User1/
Root/Text/User1/Folder2
nhưng đồng monent hiển thị của nó như
Root/css/
tree/css/
js/
images/
PHP này Mã sản phẩm:
function ListFolder($path)
{
$dir_handle = @opendir($path) or die("Unable to open $path");
//Leave only the lastest folder name
$dirname = end(explode("/", $path));
//display the target folder.
echo ("$dirname/");
while (false !== ($file = readdir($dir_handle)))
{
if($file!="." && $file!="..")
{
if (is_dir($path."/".$file))
{
//Display a list of sub folders.
ListFolder($path."/".$file);
echo "<br>";
}
}
}
//closing the directory
closedir($dir_handle);
}
ListFolder("../");
Cảm ơn bạn
thể trùng lặp tối thiểu là [PHP SPL RecursiveDirectoryIterator RecursiveIteratorIterator lấy cây đầy đủ] (http: //stackoverflow.com/questions/2418068/php-spl-recursivedirectoryiterator-recursiveiteratoriterator-retrieving-the-full) – Gordon