mkdir 在 PHP 中不工作
过去两个小时我一直在为此烦恼,我确信我正在做一些非常愚蠢的事情。
<?php
mkdir("blah", 0777);
?>
这通过命令行工作并创建文件夹。但当我尝试通过浏览器运行它时,同样的事情不起作用。有文件权限问题吗?
Have been pulling out my hair for the past 2 hours on this and am sure I am doing something really stupid.
<?php
mkdir("blah", 0777);
?>
This works through the command line and the folder gets created. But the same thing doesn't work when I try to run it through the browser. Any file permission issues?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有没有可能,在命令行下运行时,脚本会继承您的权限,但从浏览器运行时却不会?
在这种情况下,您可能希望为组设置“写入”目录权限。
Could it possibly be that while running under the command line, the script inherits your permissions, but when running from the browser it doesn't?
In that case you would want to make your directory permissions 'write' for group.
您的 Web 服务器(apache?)正在以其自己的用户身份运行,并且无权写入您正在运行 mkdir 的目录。
通过 A) 使其成为所有者,授予您的 Web 服务器的用户写入该目录的权限,B) 如果组具有写入权限,则将其添加到组中,或者 C) 授予每个人写入权限(大多数设置不建议)。
Your web server (apache?) is running as it's own user, and doesn't have permission to write to the directory you're running mkdir in.
Give your web server's user permission to write to the directory by either A) making it Owner, B) adding it to the Group if the Group has write permission, or C) give Everyone write permission (not recommended for most setups).
你可以尝试使用
umask
,当PHP用作服务器模块时,umask会在每个请求完成时恢复。you can try with the
umask
, When PHP is being used as a server module, the umask is restored when each request is finished.要使
mkdir
代码在 Linux 中运行,您需要通过sudo chmod a+w [file/path]
向该文件添加权限a+rwx
或者To make
mkdir
code run in Linux you need to add permissiona+rwx
to this file bysudo chmod a+w [file/path]
or