mkdir() not working

心已入冬 提交于 2019-12-03 12:35:18

You're missing quotes around the path name parameter.

Do all of the parent directories exist?

If not, you'll need to enable recursion (assuming PHP5 here):

mkdir('/path/to/your/dir',0777,true);

EDIT: Didn't see the hidden comment saying that every directory from var downward was set to world-writable, so I'm betting the directory path exists and the above won't be helpful. Sorry!

Are you trying to create those directories recursively, like you would do with mkdir -p on the command line? If so, specify true as the third parameter to mkdir.

And just to echo the previous suggestions, PLEASE specify the error messages you are getting. If you are not getting any, use this before your call: error_reporting(-1); // ALL messages and ini_set('display_errors', 'On');.

Have you tried with the shortest test possible?

mkdir('directory',0777);

If this does not work I would try creating with a standard CHMOD like 0755 (this is a totally random guess, maybe the server won't allow creating 0777 via PHP)

if this don't work I would say the server probably need different setup / php doesn' thave the writting right on folder, maybe you could ask your host provider?

Adam Sádovský

I have similar problem and I found out, that I have no free space left on my drive. Check with command df (on linux) how full is your drive. It is possible that root is allowed to create files and folders in this situation, because he has pre-reserved space. If you run you script from command-line as root user - there is no error, but if your script is run by apache, then error occure.

If anyone gets stuck with this problem.. there's one answer I can give you that I spend 2 hours on finding.. I tried with using a full path, and "../mydirectoryname".

Try using:

mkdir("./mydirectoryname", 0777, true);

Instead of..

mkdir("../mydirectoryname", 0777, true);

For future references, the problem might come from the possibility that the directory where you're trying to create your new directory doesn't have enough permission.

For instance, your index directory might look like this: index.php new_dirs_here

if new_dirs_here doesn't have enough permission then you can't create direcories inside.

To solve this, I'd use the command: chmod 777 new_dirs_here

I'm not worrying about security now, Just trying to solve the immediate problem. You could of course look up a better permission settings, but the idea is that your new_dirs_here should have enough permissions.

Then, your mkdir() dunction should work just fine.

Good luck

You must take the attribute in quotes:

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