• snamyar

    (@snamyar)


    Is there a way to display the number of files that are going to be listed in a table?
    For instance, my shortcode is pointing to a folder to list all word documents in that folder. I would like to see the number of files somewhere in the page like table header.

    https://wordpress.org/plugins/file-away/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author thomstark

    (@thomstark)

    Not currently a feature.

    Plugin Author thomstark

    (@thomstark)

    If it’s urgent you can create some custom javascript to count your table rows and add the total to the page.

    – install “Allow PHP in Posts and Pages” plugin.

    working code:
    ———————————————————————–
    $directory = “./upload2/” . $current_user->user_login; // dir location
    $files = scandir($directory);
    for($i = 0 ; $i < count($files) ; $i++){
    if($files[$i] !=’.’ && $files[$i] !=’..’)
    { //echo $files[$i]; echo “
    “;
    $file_new[] = $files[$i];
    }
    }
    $num_files = count($file_new)-1; // omit index.php
    echo (‘File Count: ‘ . $num_files ); // Prints the count
    ———————————————————————–

    good luck.

    Plugin Author thomstark

    (@thomstark)

    Guess350, that code isn’t going to account for File Away’s many filtering options. The file count will not match the number of files ouput to the page under an unlimited number of possible scenarios. It also doesn’t account for file away’s recursive directory iteration or directory tree navigation.

    for my case, i don’t allow user to create sub folders.
    i asked users to use zip file instead for multiple files/sub folders.
    my main purpose is to provide quick file exchange without too much complex interface.

    but, maybe one of the php experts may be able to come up with a better code to handle recursive directory.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Count files’ is closed to new replies.