PHP:  mkdir subfolder

detox1978 used Ask the Experts™
Hi All,

Ok, pretty sure this is straight forward, but i can't work it out.

Within myscript.php how do i create a folder in /admin/images


I thought it would be this;

mkdir("/admin/images/".$user_id, 0777);
chmod("/admin/images/", 0777);

Open in new window

...but it returned;

Warning: mkdir() [function.mkdir]: No such file or directory
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You are probably missing the path

mkdir("/path/to/my/dir", 0700);


Is there a way to work out the path.  As i tried the root of the webserver, but guess it should be different when referencing it locally.
If you have SSH access you can find your webroot by searching for your domain and You may get a glimpse of the path by connecting to / via ftp.

which mkdir
Above establishes the path of the command if that's the issue.

The webroot path may be something like this

Linux with Plesk:

Be sure to replace "domain.tld" with your actual domain name.

Linux with cPanel:
Senior Platform Engineer
Try something like:

mkdir($_SERVER['DOCUMENT_ROOT'] . "/admin/images/" . $user_id, 0700);

Open in new window



Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial