PHP:对文件权限感到困惑,无法取消链接安装文件?
我创建了一个 setup.php 来处理 MySQL 表的生成,作为明显的预防措施,我添加了一种在完成后将其删除的方法。由于使用 unlink(__FILE__)
是不可能的,我在 main.php?action=deleteconfig
中添加了删除代码来取消文件的链接。
setup.php
具有权限 777
,但当我取消链接时,它给了我一个权限被拒绝的错误。我的目录是 drwxr-xr-x
我的 main.php
是 -rw-r--r--
。
我是否需要将 main.php
设置为 777 才能删除 setup.php
?我对这里的文件权限以及为什么它们不起作用感到困惑。
I created a setup.php
to handle MySQL table generation, and as an obvious precaution I added a way to delete it after it was finished. As using unlink(__FILE__)
is impossible to do, I added deletion code to main.php?action=deleteconfig
to unlink the file.
setup.php
has permissions 777
, but it gives me a permission denied error when I unlink it.. My directory is drwxr-xr-x
and my main.php
is -rw-r--r--
.
Would I need to set main.php
to 777 as well before it can delete setup.php
? I am confused about file permissions here and why they do not work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
运行 php 的用户需要对该目录具有写权限才能修改其内容(即删除/创建)。因此,您可以将目录
chown
给php用户,或者将php用户添加到组中并chmod目录,以便该组拥有w
权限。The user running php needs to have write permissions for the directory in order to modify its contents (ie. delete/create). so you could
chown
the directory to the php user, or add the php user to the group and chmod the directory to so that the group haw
permissions.我最近遇到了类似的问题,在上传的文件不属于任何人/无人拥有的设置中。
为了使取消链接正常工作,请确保您使用的是要删除的文件的路径,而不是 url
I have recently run into a similar problem, in a setup where uploaded files are owned by nobody/nobody.
For the unlink to work correctly, make sure you are using the path to the file you want to delete, not the url