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:
Update: Please try the link now guys, thanks for the notes about the download link not working totally missed my attention.
Related posts:
No tags for this post.
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,
ok , i just realised that this is just the same and that the binary values translate into the correct octal values ..
nevermind
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!
The download link for this script is still broken as described above. It’s a pity.