views:

512

answers:

4

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

+3  A: 

What about this?

mkdir('c:/files/Users/'.$id)
Mark L
Well, it did the trick, but the question remains: why did the previous code not work?
WebDevHobo
Hey, in windows you have to specify the drive letter, the system won't make any assumptions.
Mark L
quite obvious why it didnt work, since the path "/files/Users/" does not exists in php+windows. The starting slash indicates an absolute path, which doesnt exists on windows.If you want the relative path, just drop the first slash.
Henri
+1  A: 

Couple of possibilities:

  1. Lose the first / since that gives an absolute path and you're looking to make a relative path -- so mkdir('files/Users/'.$id)
  2. 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.
Randy
'files/Users' already exists. All the users already exist(using phpMyAdmin for database management)
WebDevHobo
relative path versus absolute, that was it.
WebDevHobo
+1  A: 

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.

Time Machine
A: 

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

MANCHUCK
So PHP makes no attempt to detect what kind of system it's running on, but tries to guess based on the argument you pass to mkdir?
Stewart
a simple answer is yes. It already knows what OS its running on since it was complied to the system.
MANCHUCK