PDA

View Full Version : probably a noob question about mkdir()



whitej_d
09-01-2008, 01:16 AM
Ok, I want my php script to make a directory before populating it with a file but for some reason mkdir() will not work.

I have stripped the code down to what I think is the simplest possible thing and it still won't work:

<?php

mkdir("/test/talatthai/hello-world") or die("could not make directory");

?>

It gives me the following error:

Warning: mkdir() [function.mkdir]: No such file or directory in /home2/experig3/public_html/test/talatthai/test.php on line 3
could not make directory

I'm obviously doing something very stupid here, but I can't for the life of me work out what!

If anyone can give me a slap and point me in the right direction I would be very grateful.

BenInBlack
09-01-2008, 04:15 AM
you should use $_SERVER['DOCUMENT_ROOT'].

ie. mkdir($_SERVER['DOCUMENT_ROOT']."/test/talatthai/hello-world") or die("could not make directory");

without the $_SERVER['DOCUMENT_ROOT'] the first slash "/test" is taken as the root folder and since this is shared and we are in subfolders you need $_SERVER['DOCUMENT_ROOT'] to get the real path up to our folders.