PHP:  mkdir subfolder

detox1978
detox1978 used Ask the Experts™
on
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

/PHP/myScript.php
/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
Comment
Watch Question

Do more with

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

http://php.net/manual/en/function.mkdir.php

<?php
mkdir("/path/to/my/dir", 0700);
?>

Author

Commented:
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
http://support.hostgator.com/articles/hosting-guide/lets-get-started/server-path-absolute-path

Linux with Plesk:
/var/www/vhosts/domain.tld/httpdocs

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

Linux with cPanel:
/home/cpanel-username/public_html/
Senior Platform Engineer
Commented:
Try something like:

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

Open in new window

Author

Commented:
Thanks,

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