开发者

chmod() and chown() of a symlink file in PHP

开发者 https://www.devze.com 2023-01-06 10:54 出处:网络
Are there PHP com开发者_Python百科mands to change file access permissions/owner of a symlink file as opposed to those of the object the symlink points to?

Are there PHP com开发者_Python百科mands to change file access permissions/owner of a symlink file as opposed to those of the object the symlink points to?

From the shell I can

$ mkdir adir
$ ln -s adir alink
$ chmod 0700 alink         -- changes permissions of directory adir
$ chmod -h 0700 alink      -- changes permissions of file alink

but I don't see how to do the last of these in PHP other than by invoking a shell, e.g. with exec().


PHP does not support changing the permissions of symbolic links (there is no lchmod function like the lstat and lchown functions).

Linux doesn't support it, either:

POSIX does not require lchmod, and Linux does not supply it. On platforms that lack lchmod, symlinks always have the same default permissions, so the inability to change permissions is not a problem because the source that you would be copying has the same permissions (0777) as the newly created symlink destination.

On BSD, where lchmod is supported, only the 0555 bits matter (readlink() fails if the current user can't read the symlink, and all other syscalls fail with ENOENT for failure to follow the symlink if the current user can't search/execute the symlink during file name resolution), and even then, only if on a file system mounted with the symperm option.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号