Hướng dẫn how can i get a list of all the subfolders and files present in a directory using php? - Làm cách nào tôi có thể lấy danh sách tất cả các thư mục con và tệp có trong thư mục bằng php?

Cuối chương trình, nhưng để xây dựng câu trả lời được chấp nhận ...

Nếu bạn muốn có tất cả các tệp và thư mục trong AS mảng (có thể được trang bị độc đáo với JSON.Stringify trong JavaScript), bạn có thể sửa đổi chức năng thành:

function listFolderFiles($dir) { 
    $arr = array();
    $ffs = scandir($dir);

    foreach($ffs as $ff) {
        if($ff != '.' && $ff != '..') {
            $arr[$ff] = array();
            if(is_dir($dir.'/'.$ff)) {
                $arr[$ff] = listFolderFiles($dir.'/'.$ff);
            }
        }
    }

    return $arr;
}

Cho những người mới ...

Để sử dụng JSON.stringify đã nói ở trên, JS/JQuery của bạn sẽ giống như:

var ajax = $.ajax({
    method: 'POST',
    data: {list_dirs: true}
}).done(function(msg) {
    $('pre').html(
        'FILE LAYOUT
' + JSON.stringify(JSON.parse(msg), null, 4) ); });

^ Điều này giả sử bạn có một yếu tố

 trong HTML của bạn ở đâu đó. Bất kỳ hương vị nào của Ajax sẽ làm, nhưng tôi cho rằng hầu hết mọi người đang sử dụng một cái gì đó tương tự như jQuery ở trên.

Và PHP đi kèm:

if(isset($_POST['list_dirs'])) {
    echo json_encode(listFolderFiles($rootPath));
    exit();
}

nơi bạn đã có listFolderFiles từ trước.

Trong trường hợp của tôi, tôi đã đặt $rootPath của mình thành thư mục gốc của trang web ...

$rootPath; 
if(!isset($rootPath)) {
    $rootPath = $_SERVER['DOCUMENT_ROOT'];
}

Kết quả cuối cùng là một cái gì đó giống như ...

|    some_file_1487.smthng    []
|    some_file_8752.smthng    []
|    CSS    
|    |    some_file_3615.smthng    []
|    |    some_file_8151.smthng    []
|    |    some_file_7571.smthng    []
|    |    some_file_5641.smthng    []
|    |    some_file_7305.smthng    []
|    |    some_file_9527.smthng    []
|    
|    IMAGES    
|    |    some_file_4515.smthng    []
|    |    some_file_1335.smthng    []
|    |    some_file_1819.smthng    []
|    |    some_file_9188.smthng    []
|    |    some_file_4760.smthng    []
|    |    some_file_7347.smthng    []
|    
|    JSScripts    
|    |    some_file_6449.smthng    []
|    |    some_file_7864.smthng    []
|    |    some_file_3899.smthng    []
|    |    google-code-prettify    
|    |    |    some_file_2090.smthng    []
|    |    |    some_file_5169.smthng    []
|    |    |    some_file_3426.smthng    []
|    |    |    some_file_8208.smthng    []
|    |    |    some_file_7581.smthng    []
|    |    |    some_file_4618.smthng    []
|    |    
|    |    some_file_3883.smthng    []
|    |    some_file_3713.smthng    []

... and so on...

Lưu ý: Bạn sẽ không giống hệt như thế này - Tôi đã sửa đổi JSON.stringify để hiển thị các tab (đường ống dọc), căn chỉnh tất cả các giá trị có khóa, loại bỏ trích dẫn của các phím và một vài thứ khác. Tôi sẽ sửa đổi câu trả lời này với một liên kết nếu tôi có thể tải lên nó hoặc nhận đủ sự quan tâm.

Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    Đọc
    Explaination: In our PHP code, initially, it is checked whether provided path or filename is a directory or not using is_dir() function. Now, we open the directory using opendir() function and then checking whether it is getting opened or have some errors. Then we use a while loop to get names of all the subfolders, as well as files, present inside the directory with the help of readdir() function. Now we are going inside each subfolder and reading the names of all the files present inside them following a similar procedure.
    Folder Structure: 
     

    Hướng dẫn how can i get a list of all the subfolders and files present in a directory using php? - Làm cách nào tôi có thể lấy danh sách tất cả các thư mục con và tệp có trong thư mục bằng php?

    Bàn luận 
    Note: This Code have been saved as PHP file and accessed through wampserver 
     

    Với đường dẫn của thư mục và tác vụ là in tên của các thư mục con và tệp có bên trong chúng. Giải thích: Trong mã PHP của chúng tôi, ban đầu, nó được kiểm tra xem đường dẫn được cung cấp hoặc tên tệp có phải là thư mục hay không sử dụng hàm is_dir (). Bây giờ, chúng tôi mở thư mục bằng hàm opendir () và sau đó kiểm tra xem nó đang được mở hoặc có một số lỗi. Sau đó, chúng tôi sử dụng một vòng lặp trong thời gian để lấy tên của tất cả các thư mục con, cũng như các tệp, xuất hiện bên trong thư mục với sự trợ giúp của hàm readDir (). Bây giờ chúng tôi sẽ đi vào bên trong mỗi thư mục con và đọc tên của tất cả các tệp có bên trong chúng theo một quy trình tương tự.

    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    0

    Mã: & nbsp; Lưu ý: Mã này đã được lưu dưới dạng tệp PHP và được truy cập thông qua WampServer & NBSP; & NBSP;

    PHP

    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    1
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    2
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    3
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    4

    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    5
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    6
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    7
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    6
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    1

    $rootPath; 
    if(!isset($rootPath)) {
        $rootPath = $_SERVER['DOCUMENT_ROOT'];
    }
    
    1
    $rootPath; 
    if(!isset($rootPath)) {
        $rootPath = $_SERVER['DOCUMENT_ROOT'];
    }
    
    2
    $rootPath; 
    if(!isset($rootPath)) {
        $rootPath = $_SERVER['DOCUMENT_ROOT'];
    }
    
    3
    $rootPath; 
    if(!isset($rootPath)) {
        $rootPath = $_SERVER['DOCUMENT_ROOT'];
    }
    
    4
    $rootPath; 
    if(!isset($rootPath)) {
        $rootPath = $_SERVER['DOCUMENT_ROOT'];
    }
    
    5
    if(isset($_POST['list_dirs'])) {
        echo json_encode(listFolderFiles($rootPath));
        exit();
    }
    
    222

    $rootPath; 
    if(!isset($rootPath)) {
        $rootPath = $_SERVER['DOCUMENT_ROOT'];
    }
    
    8
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    5
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    6
    $rootPath; 
    if(!isset($rootPath)) {
        $rootPath = $_SERVER['DOCUMENT_ROOT'];
    }
    
    4
    |    some_file_1487.smthng    []
    |    some_file_8752.smthng    []
    |    CSS    
    |    |    some_file_3615.smthng    []
    |    |    some_file_8151.smthng    []
    |    |    some_file_7571.smthng    []
    |    |    some_file_5641.smthng    []
    |    |    some_file_7305.smthng    []
    |    |    some_file_9527.smthng    []
    |    
    |    IMAGES    
    |    |    some_file_4515.smthng    []
    |    |    some_file_1335.smthng    []
    |    |    some_file_1819.smthng    []
    |    |    some_file_9188.smthng    []
    |    |    some_file_4760.smthng    []
    |    |    some_file_7347.smthng    []
    |    
    |    JSScripts    
    |    |    some_file_6449.smthng    []
    |    |    some_file_7864.smthng    []
    |    |    some_file_3899.smthng    []
    |    |    google-code-prettify    
    |    |    |    some_file_2090.smthng    []
    |    |    |    some_file_5169.smthng    []
    |    |    |    some_file_3426.smthng    []
    |    |    |    some_file_8208.smthng    []
    |    |    |    some_file_7581.smthng    []
    |    |    |    some_file_4618.smthng    []
    |    |    
    |    |    some_file_3883.smthng    []
    |    |    some_file_3713.smthng    []
    
    ... and so on...
    
    2
    |    some_file_1487.smthng    []
    |    some_file_8752.smthng    []
    |    CSS    
    |    |    some_file_3615.smthng    []
    |    |    some_file_8151.smthng    []
    |    |    some_file_7571.smthng    []
    |    |    some_file_5641.smthng    []
    |    |    some_file_7305.smthng    []
    |    |    some_file_9527.smthng    []
    |    
    |    IMAGES    
    |    |    some_file_4515.smthng    []
    |    |    some_file_1335.smthng    []
    |    |    some_file_1819.smthng    []
    |    |    some_file_9188.smthng    []
    |    |    some_file_4760.smthng    []
    |    |    some_file_7347.smthng    []
    |    
    |    JSScripts    
    |    |    some_file_6449.smthng    []
    |    |    some_file_7864.smthng    []
    |    |    some_file_3899.smthng    []
    |    |    google-code-prettify    
    |    |    |    some_file_2090.smthng    []
    |    |    |    some_file_5169.smthng    []
    |    |    |    some_file_3426.smthng    []
    |    |    |    some_file_8208.smthng    []
    |    |    |    some_file_7581.smthng    []
    |    |    |    some_file_4618.smthng    []
    |    |    
    |    |    some_file_3883.smthng    []
    |    |    some_file_3713.smthng    []
    
    ... and so on...
    
    3
    |    some_file_1487.smthng    []
    |    some_file_8752.smthng    []
    |    CSS    
    |    |    some_file_3615.smthng    []
    |    |    some_file_8151.smthng    []
    |    |    some_file_7571.smthng    []
    |    |    some_file_5641.smthng    []
    |    |    some_file_7305.smthng    []
    |    |    some_file_9527.smthng    []
    |    
    |    IMAGES    
    |    |    some_file_4515.smthng    []
    |    |    some_file_1335.smthng    []
    |    |    some_file_1819.smthng    []
    |    |    some_file_9188.smthng    []
    |    |    some_file_4760.smthng    []
    |    |    some_file_7347.smthng    []
    |    
    |    JSScripts    
    |    |    some_file_6449.smthng    []
    |    |    some_file_7864.smthng    []
    |    |    some_file_3899.smthng    []
    |    |    google-code-prettify    
    |    |    |    some_file_2090.smthng    []
    |    |    |    some_file_5169.smthng    []
    |    |    |    some_file_3426.smthng    []
    |    |    |    some_file_8208.smthng    []
    |    |    |    some_file_7581.smthng    []
    |    |    |    some_file_4618.smthng    []
    |    |    
    |    |    some_file_3883.smthng    []
    |    |    some_file_3713.smthng    []
    
    ... and so on...
    
    4
    $rootPath; 
    if(!isset($rootPath)) {
        $rootPath = $_SERVER['DOCUMENT_ROOT'];
    }
    
    4
    |    some_file_1487.smthng    []
    |    some_file_8752.smthng    []
    |    CSS    
    |    |    some_file_3615.smthng    []
    |    |    some_file_8151.smthng    []
    |    |    some_file_7571.smthng    []
    |    |    some_file_5641.smthng    []
    |    |    some_file_7305.smthng    []
    |    |    some_file_9527.smthng    []
    |    
    |    IMAGES    
    |    |    some_file_4515.smthng    []
    |    |    some_file_1335.smthng    []
    |    |    some_file_1819.smthng    []
    |    |    some_file_9188.smthng    []
    |    |    some_file_4760.smthng    []
    |    |    some_file_7347.smthng    []
    |    
    |    JSScripts    
    |    |    some_file_6449.smthng    []
    |    |    some_file_7864.smthng    []
    |    |    some_file_3899.smthng    []
    |    |    google-code-prettify    
    |    |    |    some_file_2090.smthng    []
    |    |    |    some_file_5169.smthng    []
    |    |    |    some_file_3426.smthng    []
    |    |    |    some_file_8208.smthng    []
    |    |    |    some_file_7581.smthng    []
    |    |    |    some_file_4618.smthng    []
    |    |    
    |    |    some_file_3883.smthng    []
    |    |    some_file_3713.smthng    []
    
    ... and so on...
    
    2__

    |    some_file_1487.smthng    []
    |    some_file_8752.smthng    []
    |    CSS    
    |    |    some_file_3615.smthng    []
    |    |    some_file_8151.smthng    []
    |    |    some_file_7571.smthng    []
    |    |    some_file_5641.smthng    []
    |    |    some_file_7305.smthng    []
    |    |    some_file_9527.smthng    []
    |    
    |    IMAGES    
    |    |    some_file_4515.smthng    []
    |    |    some_file_1335.smthng    []
    |    |    some_file_1819.smthng    []
    |    |    some_file_9188.smthng    []
    |    |    some_file_4760.smthng    []
    |    |    some_file_7347.smthng    []
    |    
    |    JSScripts    
    |    |    some_file_6449.smthng    []
    |    |    some_file_7864.smthng    []
    |    |    some_file_3899.smthng    []
    |    |    google-code-prettify    
    |    |    |    some_file_2090.smthng    []
    |    |    |    some_file_5169.smthng    []
    |    |    |    some_file_3426.smthng    []
    |    |    |    some_file_8208.smthng    []
    |    |    |    some_file_7581.smthng    []
    |    |    |    some_file_4618.smthng    []
    |    |    
    |    |    some_file_3883.smthng    []
    |    |    some_file_3713.smthng    []
    
    ... and so on...
    
    9JSON.stringify0 JSON.stringify1 JSON.stringify2
    $rootPath; 
    if(!isset($rootPath)) {
        $rootPath = $_SERVER['DOCUMENT_ROOT'];
    }
    
    4 JSON.stringify4

    |    some_file_1487.smthng    []
    |    some_file_8752.smthng    []
    |    CSS    
    |    |    some_file_3615.smthng    []
    |    |    some_file_8151.smthng    []
    |    |    some_file_7571.smthng    []
    |    |    some_file_5641.smthng    []
    |    |    some_file_7305.smthng    []
    |    |    some_file_9527.smthng    []
    |    
    |    IMAGES    
    |    |    some_file_4515.smthng    []
    |    |    some_file_1335.smthng    []
    |    |    some_file_1819.smthng    []
    |    |    some_file_9188.smthng    []
    |    |    some_file_4760.smthng    []
    |    |    some_file_7347.smthng    []
    |    
    |    JSScripts    
    |    |    some_file_6449.smthng    []
    |    |    some_file_7864.smthng    []
    |    |    some_file_3899.smthng    []
    |    |    google-code-prettify    
    |    |    |    some_file_2090.smthng    []
    |    |    |    some_file_5169.smthng    []
    |    |    |    some_file_3426.smthng    []
    |    |    |    some_file_8208.smthng    []
    |    |    |    some_file_7581.smthng    []
    |    |    |    some_file_4618.smthng    []
    |    |    
    |    |    some_file_3883.smthng    []
    |    |    some_file_3713.smthng    []
    
    ... and so on...
    
    9JSON.stringify6JSON.stringify7JSON.stringify8JSON.stringify9

    0
    1 
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    2
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    3
    4
    $rootPath; 
    if(!isset($rootPath)) {
        $rootPath = $_SERVER['DOCUMENT_ROOT'];
    }
    
    4
    4__

    |    some_file_1487.smthng    []
    |    some_file_8752.smthng    []
    |    CSS    
    |    |    some_file_3615.smthng    []
    |    |    some_file_8151.smthng    []
    |    |    some_file_7571.smthng    []
    |    |    some_file_5641.smthng    []
    |    |    some_file_7305.smthng    []
    |    |    some_file_9527.smthng    []
    |    
    |    IMAGES    
    |    |    some_file_4515.smthng    []
    |    |    some_file_1335.smthng    []
    |    |    some_file_1819.smthng    []
    |    |    some_file_9188.smthng    []
    |    |    some_file_4760.smthng    []
    |    |    some_file_7347.smthng    []
    |    
    |    JSScripts    
    |    |    some_file_6449.smthng    []
    |    |    some_file_7864.smthng    []
    |    |    some_file_3899.smthng    []
    |    |    google-code-prettify    
    |    |    |    some_file_2090.smthng    []
    |    |    |    some_file_5169.smthng    []
    |    |    |    some_file_3426.smthng    []
    |    |    |    some_file_8208.smthng    []
    |    |    |    some_file_7581.smthng    []
    |    |    |    some_file_4618.smthng    []
    |    |    
    |    |    some_file_3883.smthng    []
    |    |    some_file_3713.smthng    []
    
    ... and so on...
    
    9
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    5
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    6
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    7
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    6
    1
    if(isset($_POST['list_dirs'])) {
        echo json_encode(listFolderFiles($rootPath));
        exit();
    }
    
    0

    listFolderFiles6listFolderFiles7

    if(isset($_POST['list_dirs'])) {
        echo json_encode(listFolderFiles($rootPath));
        exit();
    }
    
    3
    1
    if(isset($_POST['list_dirs'])) {
        echo json_encode(listFolderFiles($rootPath));
        exit();
    }
    
    5

    $rootPath1

    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    5
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    6______777

    $rootPath6

    $rootPath; 
    if(!isset($rootPath)) {
        $rootPath = $_SERVER['DOCUMENT_ROOT'];
    }
    
    2
    $rootPath; 
    if(!isset($rootPath)) {
        $rootPath = $_SERVER['DOCUMENT_ROOT'];
    }
    
    3$rootPath9
    $rootPath; 
    if(!isset($rootPath)) {
        $rootPath = $_SERVER['DOCUMENT_ROOT'];
    }
    
    5______7777

    0
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    5
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    6$rootPath9
    |    some_file_1487.smthng    []
    |    some_file_8752.smthng    []
    |    CSS    
    |    |    some_file_3615.smthng    []
    |    |    some_file_8151.smthng    []
    |    |    some_file_7571.smthng    []
    |    |    some_file_5641.smthng    []
    |    |    some_file_7305.smthng    []
    |    |    some_file_9527.smthng    []
    |    
    |    IMAGES    
    |    |    some_file_4515.smthng    []
    |    |    some_file_1335.smthng    []
    |    |    some_file_1819.smthng    []
    |    |    some_file_9188.smthng    []
    |    |    some_file_4760.smthng    []
    |    |    some_file_7347.smthng    []
    |    
    |    JSScripts    
    |    |    some_file_6449.smthng    []
    |    |    some_file_7864.smthng    []
    |    |    some_file_3899.smthng    []
    |    |    google-code-prettify    
    |    |    |    some_file_2090.smthng    []
    |    |    |    some_file_5169.smthng    []
    |    |    |    some_file_3426.smthng    []
    |    |    |    some_file_8208.smthng    []
    |    |    |    some_file_7581.smthng    []
    |    |    |    some_file_4618.smthng    []
    |    |    
    |    |    some_file_3883.smthng    []
    |    |    some_file_3713.smthng    []
    
    ... and so on...
    
    2
    |    some_file_1487.smthng    []
    |    some_file_8752.smthng    []
    |    CSS    
    |    |    some_file_3615.smthng    []
    |    |    some_file_8151.smthng    []
    |    |    some_file_7571.smthng    []
    |    |    some_file_5641.smthng    []
    |    |    some_file_7305.smthng    []
    |    |    some_file_9527.smthng    []
    |    
    |    IMAGES    
    |    |    some_file_4515.smthng    []
    |    |    some_file_1335.smthng    []
    |    |    some_file_1819.smthng    []
    |    |    some_file_9188.smthng    []
    |    |    some_file_4760.smthng    []
    |    |    some_file_7347.smthng    []
    |    
    |    JSScripts    
    |    |    some_file_6449.smthng    []
    |    |    some_file_7864.smthng    []
    |    |    some_file_3899.smthng    []
    |    |    google-code-prettify    
    |    |    |    some_file_2090.smthng    []
    |    |    |    some_file_5169.smthng    []
    |    |    |    some_file_3426.smthng    []
    |    |    |    some_file_8208.smthng    []
    |    |    |    some_file_7581.smthng    []
    |    |    |    some_file_4618.smthng    []
    |    |    
    |    |    some_file_3883.smthng    []
    |    |    some_file_3713.smthng    []
    
    ... and so on...
    
    3
    |    some_file_1487.smthng    []
    |    some_file_8752.smthng    []
    |    CSS    
    |    |    some_file_3615.smthng    []
    |    |    some_file_8151.smthng    []
    |    |    some_file_7571.smthng    []
    |    |    some_file_5641.smthng    []
    |    |    some_file_7305.smthng    []
    |    |    some_file_9527.smthng    []
    |    
    |    IMAGES    
    |    |    some_file_4515.smthng    []
    |    |    some_file_1335.smthng    []
    |    |    some_file_1819.smthng    []
    |    |    some_file_9188.smthng    []
    |    |    some_file_4760.smthng    []
    |    |    some_file_7347.smthng    []
    |    
    |    JSScripts    
    |    |    some_file_6449.smthng    []
    |    |    some_file_7864.smthng    []
    |    |    some_file_3899.smthng    []
    |    |    google-code-prettify    
    |    |    |    some_file_2090.smthng    []
    |    |    |    some_file_5169.smthng    []
    |    |    |    some_file_3426.smthng    []
    |    |    |    some_file_8208.smthng    []
    |    |    |    some_file_7581.smthng    []
    |    |    |    some_file_4618.smthng    []
    |    |    
    |    |    some_file_3883.smthng    []
    |    |    some_file_3713.smthng    []
    
    ... and so on...
    
    4$rootPath9

    listFolderFiles6JSON.stringify0 $rootPath9

    4
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    08
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    4

    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    10
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    11

    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    12
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    11

    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    14
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    11

    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    16
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    11

    $rootPath6

    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    11

    |    some_file_1487.smthng    []
    |    some_file_8752.smthng    []
    |    CSS    
    |    |    some_file_3615.smthng    []
    |    |    some_file_8151.smthng    []
    |    |    some_file_7571.smthng    []
    |    |    some_file_5641.smthng    []
    |    |    some_file_7305.smthng    []
    |    |    some_file_9527.smthng    []
    |    
    |    IMAGES    
    |    |    some_file_4515.smthng    []
    |    |    some_file_1335.smthng    []
    |    |    some_file_1819.smthng    []
    |    |    some_file_9188.smthng    []
    |    |    some_file_4760.smthng    []
    |    |    some_file_7347.smthng    []
    |    
    |    JSScripts    
    |    |    some_file_6449.smthng    []
    |    |    some_file_7864.smthng    []
    |    |    some_file_3899.smthng    []
    |    |    google-code-prettify    
    |    |    |    some_file_2090.smthng    []
    |    |    |    some_file_5169.smthng    []
    |    |    |    some_file_3426.smthng    []
    |    |    |    some_file_8208.smthng    []
    |    |    |    some_file_7581.smthng    []
    |    |    |    some_file_4618.smthng    []
    |    |    
    |    |    some_file_3883.smthng    []
    |    |    some_file_3713.smthng    []
    
    ... and so on...
    
    9JSON.stringify0
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    08
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    4

    0
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    11

    $rootPath; 
    if(!isset($rootPath)) {
        $rootPath = $_SERVER['DOCUMENT_ROOT'];
    }
    
    1
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    11

    if(isset($_POST['list_dirs'])) {
        echo json_encode(listFolderFiles($rootPath));
        exit();
    }
    
    6
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    11

    if(isset($_POST['list_dirs'])) {
        echo json_encode(listFolderFiles($rootPath));
        exit();
    }
    
    1
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    11

    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    11

    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    33

    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    34

    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    35

    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    36

    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    37
    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    38

    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    39

    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    40

    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    41

    var ajax = $.ajax({
        method: 'POST',
        data: {list_dirs: true}
    }).done(function(msg) {
        $('pre').html(
            'FILE LAYOUT
    ' + JSON.stringify(JSON.parse(msg), null, 4) ); });
    42

    Output:   
     

    Hướng dẫn how can i get a list of all the subfolders and files present in a directory using php? - Làm cách nào tôi có thể lấy danh sách tất cả các thư mục con và tệp có trong thư mục bằng php?


    Làm thế nào để tôi có được một danh sách tất cả các thư mục và thư mục con?

    Mở tệp Explorer trong Windows. ....
    Nhấp vào thanh địa chỉ và thay thế đường dẫn tệp bằng cách nhập CMD sau đó nhấn Enter ..
    Điều này sẽ mở một lời nhắc lệnh màu đen và trắng hiển thị đường dẫn tệp trên ..
    Loại dir /a: d. ....
    Bây giờ nên có một tệp văn bản mới gọi là danh sách thư mục trong thư mục trên ..

    Làm cách nào để liệt kê các tệp trong tất cả các thư mục con?

    Theo mặc định, LS chỉ liệt kê một thư mục.Nếu bạn đặt tên cho một hoặc nhiều thư mục trên dòng lệnh, LS sẽ liệt kê từng thư mục.Tùy chọn -R (Uppercase R) liệt kê tất cả các thư mục con, đệ quy.

    Làm cách nào để xem tất cả các thư mục con cùng một lúc?

    Có một số cách để hiển thị một thư mục trong File Explorer: Nhấp vào thư mục nếu nó được liệt kê trong ngăn điều hướng.Nhấp vào một thư mục trong thanh địa chỉ để hiển thị các thư mục con của nó.Bấm đúp vào một thư mục trong danh sách tệp và thư mục để hiển thị bất kỳ thư mục con nào.Double-click on a folder in the file and folder listing to display any subfolders.

    Làm cách nào để có được một danh sách các tệp trong một thư mục trong PHP?

    Bạn có thể esay và chỉ cần nhận danh sách tệp trong thư mục trong PHP.Hàm scandir () trong PHP là một hàm sẵn được sử dụng để trả về một mảng các tệp và thư mục của thư mục được chỉ định.Hàm scandir () liệt kê các tệp và thư mục có trong một đường dẫn được chỉ định.The scandir() function in PHP is an inbuilt function which is used to return an array of files and directories of the specified directory. The scandir() function lists the files and directories which are present inside a specified path.