>/D_
Published on

Displaying File Permissions with PHP

Authors
  • avatar
    Name
    Frank
    Twitter

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.