Found this bit of code in FrogCms
function isWritable($file=null) {
$perms = fileperms($file);
if (is_writable($file) || ($perms & 0x0080) || ($perms & 0x0010) || ($perms & 0x0002))
return true;
}
I had a hard time understanding this part
(is_writable($file) || ($perms & 0x0080) || ($perms & 0x0010) || ($perms & 0x0002))
After doing some research i know that 0x0080 is permission for owner, 0x0010 is permission for group and 0x0002 is permission for other.Where do this value come form? Is this is a predetermined value for permission system?
And can someone explain to me for example how $perms & 0x0080 resolve to true, cause for example fileperms(__FILE__) return a value like 33206.How can u
compare 33206 with 0x0080?
The constants you refer to (
0x0080etc) do not have the exact meanings you think they do. See thefilepermsdocumentation:Also, you are not comparing them, you are performing a bitwise AND.
Since the result is non-zero, this means that the particular file is owner-writable.
But what does the code you give do?
Well, it returns
trueif and only if the file is writable by any of the following:is_writable)This certainly looks like illogical and buggy to me, because e.g.:
true; however, that certainly does not mean the file is writable for you, unless you are the owner!is_writablecheck would be superfluous and at the very least confusing.