mkdir not working in PHP

僤鯓⒐⒋嵵緔 提交于 2019-12-10 13:29:53

问题


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?


回答1:


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.




回答2:


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).




回答3:


you can try with the umask, When PHP is being used as a server module, the umask is restored when each request is finished.

$old = umask(0); 
mkdir($path,0777); 
umask($old); 


来源:https://stackoverflow.com/questions/2215849/mkdir-not-working-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!