Environment info:
*Windows Vista
*PHP 5.2.9-2
I'm working on a project. Let's say it's name simply "project". My php files meant for user-interaction will be found at
project/file.php
Now, I have a database behind this and some maps, which contain classes and configuration files in general. There is also a map for the users, in which I store images they might upload. For instance:
project/files/Users/0/profilePic.jpg
The number corresponds with the user_id in the database.
My register.php
file contains this line of code:
mkdir('/files/Users/'.$id)
The $id
variable is the biggest id number in the database, plus 1.
But it won't work. I checked the folders, I have both read and write permissions(I am admin on my machine).
What am I doing wrong?
Note: the right to tell me there's a better way to organize this reserved to those who can give me a helpful answer. :P
What about this?
mkdir('c:/files/Users/'.$id)
Couple of possibilities:
- Lose the first / since that gives an absolute path and you're looking to make a relative path -- so mkdir('files/Users/'.$id)
- Does files/Users already exist (i.e., is there already user 0, user 1, etc.)? If not, you'll need to make them first or do mkdir('files/Users/'.$id, 077, true) to recursively create the directories.
In windows, a path does not start with '/' but with a drive letter. Just remove the first slash (so '/files/users/' becomes 'files/users/').
Further, what Mark said.
PHP states that it makes the best attempt at converting the / between systems. by doing:
mkdir('/files/users');
Confused PHP into thinking it was on a *NIX system. By setting the root to c:, it was now able to properly parse the parameter and deduce that it was a windows system
来源:https://stackoverflow.com/questions/1324462/cant-create-a-folder-with-mkdir