SEO, PHP and Javascript Web Dev

Search Engine Optimisation, Web Development and Network Administration Ramblings

-->
12  01 2007

Displaying File Permissions with PHP

For whatever reason you may need to display file permissions for one of your websites. I have thrown together a very basic script which will recursively (yay recursion) navigate your filesystem and save the folder/filenames and their respective file permissions into an associative array. The script then displays the array very basically.

Due to its simplicity this script is definitely not feature rich, but the opportunity is there to build on this script very easily.

The script uses the stat() function which can be used to output all sorts of useful details about a file such as:

device
inode
inode protection mode
number of links
user id of owner
group id owner
device type if inode device *
size in bytes
time of last access
time of last modification
time of last change
blocksize for filesystem I/O *
number of blocks allocated

For this script I used inode protection mode, which looked to me to be a decimal representation of the octal number representing file permissions (e.g: 0777) - so I used decoct() to translate and voila.

There were a couple of numbers tacked on the front of the inode protection mode value, probably for all those other little permissions denoting whether the inode belongs to a folder or file, sticky permissions, maybe even set uid and set gid - I didn’t bother to find out, the last three digits is all that is needed in order to view the relevant file permissions.

*At the core of this script is code to recursively traverse a filesystem using PHP which I found excellent examples of at Zend.

Download the Script:

File Permissions with PHP

Update: Please try the link now guys, thanks for the notes about the download link not working totally missed my attention.

Share this Post:
  • Reddit
  • Sphinn
  • del.icio.us
  • Digg
  • e-mail
  • Mixx
  • Google
  • StumbleUpon

Related posts:

  1. Using a Splash Page
  2. Using NTFSClone.
  3. Using Scriptaculous for a simple Image Morph
  4. Group Policy File System and Registry Rights Not Applying
  5. Voting System for Increased Inbound Links Using PHP

No tags for this post.
« Apple announces IPhone release!
302 or to not 302, or to 301, or just nothing? »

4 Responses to “Displaying File Permissions with PHP”

  1. hi ,

    does this script actually work ?
    because to me its seems that you have to look at the inode protection mode number in binary , and the last 9 bits represent the flags for the r/w/x permissions for owner, group and others
    so
    ….100100100 would mean r–r–r– ,
    ….111111101 would mean rwxrwxr-x

    and so on…

    regards,

  2. ok , i just realised that this is just the same and that the binary values translate into the correct octal values ..
    nevermind ;)

  3. The download link for this script is broken. When I click on the link to download the zip file, it takes me a page (not a zip file!) which say “Sorry, no posts matched your criteria, please try and search again.”
    Please fix and advise me when it is working, as I would really like to see this script.
    Thanks!

  4. The download link for this script is still broken as described above. It’s a pity.

Leave a Reply

-->
  • Photography