php and making folders (mkdir)

Programming, for all ages and all languages.
Post Reply
cloudee1

php and making folders (mkdir)

Post by cloudee1 »

I am able to create one level just fine, but I want to make two! This code creates one folder, but it just won't make that second folder inside the first.

Code: Select all

// Create a folder 
   $pagefolder=$_POST['pagefolder'];
   exec("mkdir $pagefolder"); 

// now place a folder in that folder.
   $url_images = $_POST['url_images'];
   $picfolder  = $pagefolder;
   $picfolder .='/';
   $picfolder .=$url_images;
   exec("mkdir $picfolder"); 
Does anyone know if this is even possible, and if so then how? I am not looking to set permissions or any other fanciness, just plain old folders.
Warrior

Re:php and making folders (mkdir)

Post by Warrior »

I'm not sure, if anything change directories to the newly created one, create the second folder, then change back to the root folder.
Simon

Re:php and making folders (mkdir)

Post by Simon »

This should do what you're after:

Code: Select all

mkdir -p firstdir/seconddir/thirddir
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:php and making folders (mkdir)

Post by bubach »

Or you could use php's mkdir() function in wich:
mkdir("test1/test2");
works just fine..
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
Post Reply