I've looked for hours but I can't find the script that I need, and I'm not good enough at PHP to write it myself, so I was wondering if someone could share some code with me.

All I need is a script that will list all the files in a directory, and display the filesize next to the filename. Also.. since I have over 1,000 files in the directory, is it possible to make it display like 100 per page or something?

Any help is greatly appreciated.

    tr1x wrote:

    I've looked for hours but I can't find the script that I need, and I'm not good enough at PHP to write it myself, so I was wondering if someone could share some code with me.

    All I need is a script that will list all the files in a directory, and display the filesize next to the filename. Also.. since I have over 1,000 files in the directory, is it possible to make it display like 100 per page or something?

    Any help is greatly appreciated.

    You can start here.

      That would be waaaay too much overhead for what you're doing. You could easily do a simple shell command (if allowed) to "ls -ohA" which would give you an output of something like:

      [root@apollo httpdocs]# ls -ohA
      total 48K
      drwxr-xr-x   2 bpatters 4.0K Jun 10 20:30 css
      -rwxr-xr-x   1 bpatters  18K Jun 10 20:30 favicon.ico
      drwxr-xr-x   5 bpatters 4.0K Jun 10 20:30 img
      -rwxr-xr-x   1 bpatters 7.0K Jun 10 20:30 index.html
      drwxr-xr-x   2 bpatters 4.0K Jun 10 20:30 picture_library
      drwxr-xr-x   2 root     4.0K Jun 10 20:30 plesk-stat
      drwxr-xr-x  11 bpatters 4.0K Jun 10 20:30 test
      

      Then you can pick apart as you need (the"h" flag means "human readable", otherwise you could remove it and you'd see things like 4096 as the size).

      The other option is to [man]clearstatcache/man before you list the directory, use [man]glob/man to get everything in the directory, and then use a while, foreach, or for loop to go over the resulting array and use [man]stat/man to get an array of information about the file(s).

      Either way will work. One might be slightly faster (the "ls -ohA") only because you're running a raw command, and not going through PHP to do gather individual file info.

        Write a Reply...