文件权限混乱
在 FrogCms 中找到这段代码
function isWritable($file=null) {
$perms = fileperms($file);
if (is_writable($file) || ($perms & 0x0080) || ($perms & 0x0010) || ($perms & 0x0002))
return true;
}
我很难理解这部分
(is_writable($file) || ($perms & 0x0080) || ($perms & 0x0010) || ($perms & 0x0002))
经过一些研究我知道 0x0080
是所有者的权限,0x0010
是组的权限,>0x0002
是对其他人的许可。这个值从哪里来?这是权限系统的预定值吗?
有人可以向我解释一下 $perms & 是如何实现的吗? 0x0080
解析为 true,因为例如 fileperms(__FILE__)
返回类似 33206 的值。你如何才能 比较 33206 和 0x0080?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您引用的常量(
0x0080
等)并不具有您认为的确切含义。请参阅fileperms
文档:另外,您不是比较它们,您正在执行按位AND。
由于结果非零,这意味着特定文件是所有者可写的。
但是您给出的代码是做什么的?
好吧,当且仅当文件可由以下任何写入时,它才会返回
true
is_writable
检查)这对我来说当然看起来不合逻辑且有问题,因为例如:
真
;但是,这当然并不意味着该文件对您来说是可写的,除非您是所有者!is_writable
检查将是多余的,至少会造成混乱。The constants you refer to (
0x0080
etc) do not have the exact meanings you think they do. See thefileperms
documentation: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
true
if 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_writable
check would be superfluous and at the very least confusing.它们是权限位的十六进制等效项,通常以八进制指定。
是的。
非零值为 true。
They're hexadecimal equivalents of the permission bits, normally specified in octal.
Yes.
Non-zero values are true.