mkdir()不工作php

At the end of my script, I call this:

if (!file_exists("user/$u")) {
    mkdir("user/$u", 0755);
}

However it does not create the folder. The script that calls this statement is in the root dir of my project.

I am using XAMPP on Mac Yosemite if thats any help.

I have an error:

PHP Warning: mkdir(): No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/meeu/index.php on line 152

line 152 being: mkdir("user/$u", 0755);

Edit:

I now have fixed the file path, however I var dump the mkdir and get this error:

PHP Warning: mkdir(): Permission denied in /Applications/XAMPP/xamppfiles/htdocs/meeu/index.php on line 152

I'll take a stab at this. Your issue is most likely due to the fact that you're trying to mkdir() a relative path and not an absolute path.

You should try something like this:

if (!file_exists(getcwd() . "user/$u")) {
    mkdir(getcwd() . "user/$u", 0755);
}

References


Also, as stated in the comments, turn on error reporting. (This is a must, every time you develop. Stop any issues before they arise).

ini_set('display_errors', 1);
error_reporting(E_ALL);