Author Options:

How to create new folder in php? Answered

i am trying to create a folder using php, i have used the mkdir command to make a folder, however i would like it to make a folder based on the username of the person who is currently logged in. so far i have
<title> Upload Form </title>
mkdir("c:/xampp/htdocs/user/", 0700);

I would liek it to create a folder after (/user/) and use the username of the person logged in
("myusername") as the new folders name, how do i do this?


.  Try:
$myusername = "NachoMahma";
   $myNewFolderPath = "c:/xampp/htdocs/user/" . $myusername;
   if ( mkdir($myNewFolderPath, 0700) ) {
      // folder created
   } else {
      // something went wrong
.  You may have to use a $_SESSION variable instead of $myusername, but I'm not familiar with using sessions in PHP so I can't say for sure.
.  Since you didn't escape any chars in yopur mkdir string, I'm assuming none need to be escaped.
.  BTW, according to the PHP docs, "This function* has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged."


with a little bit of tweaking, worked like a charm, exept for the fact the folder created mached your username :D lol

Hi comsa42, could you post your solution please i'm working on something similar and am having trouble. Thanks!