Jump to content

mkdir subfolder


lvertel

Recommended Posts

hello people

 

here is my simple problem :

 

							// CREATING ARTIST FOLDER

								mkdir("users/".$username."");				
								chmod("users/".$username."",0777);

								mkdir("users/".$username."/".$name_artist."/images" );
								chmod("users/".$username."/".$name_artist."/images",0777);

								mkdir("users/".$username."/".$name_artist."/images/thumbs");
								chmod("users/".$username."/".$name_artist."/images/thumbs",0777);
							// END CREATING ARTIST FOLDER

 

i am having 3 MKDIR's...

 

first one is working, but the other 2 doesnt... .what is the prob :S ????

Link to comment
Share on other sites

k, then:

<?php
  mkdir("users/".$username."/".$name_artist."/images/thumbs",0777,true);
  chmod("users/".$username."",0777);
  chmod("users/".$username."/".$name_artist."/images",0777);
  chmod("users/".$username."/".$name_artist."/images/thumbs",0777);
?>

the mkdir() with that true on the end should recursively create all the folders

Link to comment
Share on other sites

damn, still doesnt work...

 

basically this is what i have :

 

-ROOT

    -USERS

    -SCRIPTS

  -IMAGES

 

 

my php files are in root folder,and i want to create those folders in USERS folder.

 

i tried your code but i cant ..it says : "[17:23:05] 550 /httpdocs/users/-4/bib: No such file or directory" (in ftp), and permissions are at 700...so i cant even delete...

 

hmmm, i really wonder how could i create those folders in USER ??

 

 

 

Link to comment
Share on other sites

Here's a function to handle this

function mkdir_recursive($pathname, $mode)
{
    is_dir(dirname($pathname)) || mkdir_recursive(dirname($pathname), $mode);
    return is_dir($pathname) || @mkdir($pathname, $mode);
}

 

then you would use it like this

$old=umask(0); 
$path="users/".$username."/".$name_artist."/images/tumbs",0777); 
mkdir_recursive($path, 0777); 
umask($old); 

hello people

 

here is my simple problem :

 

							// CREATING ARTIST FOLDER

								mkdir("users/".$username."");				
								chmod("users/".$username."",0777);

								mkdir("users/".$username."/".$name_artist."/images" );
								chmod("users/".$username."/".$name_artist."/images",0777);

								mkdir("users/".$username."/".$name_artist."/images/thumbs");
								chmod("users/".$username."/".$name_artist."/images/thumbs",0777);
							// END CREATING ARTIST FOLDER

 

i am having 3 MKDIR's...

 

first one is working, but the other 2 doesnt... .what is the prob :S ????

Link to comment
Share on other sites

ok...let's try this:

<?php
  $folder = "users/{$username}/{$name_artist}/images/thumbs";
  echo "Trying to create folders: $path<br />";
  $paths = explode('/',$folder);
  $path = "";
  for($n=0;$n < count($paths);$n++){
    $path .= $paths[$n].'/';
    mkdir($path,0777) or die("Could not make: $path");
    chmod($path,0777) or die("Could not chmod: $path");
    print "Done with: $path<br />";
  }
  print "Done!";
?>

Link to comment
Share on other sites

sorry...should test to see if the folder exists:

<?php
  $folder = "users/{$username}/{$name_artist}/images/thumbs";
  echo "Trying to create folders: $path<br />";
  $paths = explode('/',$folder);
  $path = "";
  for($n=0;$n < count($paths);$n++){
    $path .= $paths[$n].'/';
    if(is_dir($path))
      print "Folder already exists: $path<br />";
    else
      mkdir($path,0777) or die("Could not make: $path");
    chmod($path,0777) or die("Could not chmod: $path");
    print "Done with: $path<br />";
  }
  print "Done!";
?>

Link to comment
Share on other sites

lol, nothing comes out...

 

anyway, i dont understand why u try to echo : "trying to create folders : $path....

 

when path wasnt declared yet ???? lol

 

you are correct...i meant $folder for that print statement:

<?php
  $folder = "users/{$username}/{$name_artist}/images/thumbs";
  echo "Trying to create folders: $folder<br />";
  $paths = explode('/',$folder);
  $path = "";
  for($n=0;$n < count($paths);$n++){
    $path .= $paths[$n].'/';
    if(is_dir($path))
      print "Folder already exists: $path<br />";
    else
      mkdir($path,0777) or die("Could not make: $path");
    chmod($path,0777) or die("Could not chmod: $path");
    print "Done with: $path<br />";
  }
  print "Done!";
?>

Link to comment
Share on other sites

grrrr

i tried it and this is the result :

 

Trying to create folders: users/lvertel/ppp/images/thumbs

Folder already exists: users/

Could not chmod: users/

 

it didnt create the folder, i guess it sees that the folder USERS is already here so it dont create subfolders :s

Link to comment
Share on other sites

I guess that's the point...

By using that explode system, the first time you're attempting to create "users/".

That exists already, so you get error.

You can try by setting $n=1 in the first for... but then it tries to create "Ivertel/" and this does exists also if I get it right, isn't it?

Actually what's the point in all that explode stuff?

all 777...

 

i think its the problem that he wants to create a folder users/etc...

n then he see users is already made, so he stops :s

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.