Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts

    include filesizes in PHP directory list

    My apologies if this has been asked before - I couldn't find it in search ..

    I have a listing script like this:

    PHP Code:
    <?



    //define the path as relative to here
    $path ".";

    //open directory for list
    $dir_handle opendir($path) or die("Unable to open $path");




    //print filenames function
    function printFileNames($ext) {
        global 
    $docList,$dir_handle;
        while (
    $file readdir($dir_handle)) {
            if(
    ereg("\.".$ext,$file)) {
                
    $docList .= "\t<li><a href=\"$file\" target=\"_blank\">$file</a></li>\n";
                }
            }
        }





    //list of word documents
    $docList "<p>The following documents are available in MS Word format:";
    $docList .= "<ul>\n";
    printFileNames("doc");
    $docList .= "</ul>\n";

    //echo list
    echo ($docList);




    //close directory
    closedir($dir_handle);

    ?>

    Is there a way I can include in the output the size of each file, without opening them all

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Maybe I'm misunderstanding you, but couldn't you just make use of the filesize() function?
    http://www.php.net/manual/en/function.filesize.php

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That's ideal, thank you (note to self - check documentation before asking questions )


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •