问题
My code
mkdir("/some/absolute/path",0777);
and
mkdir("relative/path", 0777);
is not working, safe mode is turned off, and I've even tried setting all of the parent folders to 777.
Any ideas?
EDIT: I do have error reporting turned on, in my frustration I've 777'd the whole path just to make sure that, that isn't the issue. It's gotta be something stupidly simple going on.
EDIT EDIT: Upvotes for everyone who responded with suggestions... But I'm not going to select an answer since this still isn't resolved, but then again I think this is going to be one of those ones left open forever.
EDIT x 3: So I have the most unsatisfactory resolution to this question ever... I started with a clean VM image, retried it and it works now. No joke.
回答1:
You're missing quotes around the path name parameter.
回答2:
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!
回答3:
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');
.
回答4:
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?
回答5:
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.
回答6:
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);
回答7:
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
回答8:
You must take the attribute in quotes:
mkdir('path/to/your/dir','0777');
来源:https://stackoverflow.com/questions/3113028/mkdir-not-working