Mkdir() help please


I am trying to write a script that creates a new folder made up of a given username, it works:

  $username = $_POST['username'];
  $targetdirectory = "usr/bin/";

What I want is the script to create the folder back two folders, i.e. …/…/usr/bin/$username

How do I get it to point two directories up? I’ve tried:

  $username = $_POST['username'];
  $targetdirectory = "../../usr/bin/";

but no joy.

Any help is greatly appreciated!



does PHP have access to write into/make folders in that directory?

Yes it does - well at least I think it does.

The directory should be created in:


The script that is do achieve that is:


I hope that makes sense.

does public_html/xxxxx/usr/bin exist?

i think your problem may be that you are trying to use a relative path to create these folder. I would suggest creating some sort of config file or if you already have one creating a variable that contains a absolute path to the folder.

$config[‘base_path’] = ‘/home/public_html/’;

then you can use this later on in your script:

$targetDir = $config[‘base_path’] . ‘bin/usr/’;

Hope that makes sense

StartLion - yes that directory exists. I want to create a new folder within that directory with the name = $username (when a user is added to the database).

Hansie - thanks for that, that would be a good idea, I can then use it for removing a directory when a user is deleted.