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
https://forums.phpfreaks.com/topic/150885-mkdir-subfolder/
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
https://forums.phpfreaks.com/topic/150885-mkdir-subfolder/#findComment-792725
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
https://forums.phpfreaks.com/topic/150885-mkdir-subfolder/#findComment-792735
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
https://forums.phpfreaks.com/topic/150885-mkdir-subfolder/#findComment-792741
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
https://forums.phpfreaks.com/topic/150885-mkdir-subfolder/#findComment-792785
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
https://forums.phpfreaks.com/topic/150885-mkdir-subfolder/#findComment-792827
Share on other sites

echo out your variables and make sure they're right. Because in windows you can't create a "-4" folder.  That's what causing the problem.  The function I put up there would work fine if the folder name was valid.

echo "Username: ".$username."<br>"; 
echo "Name_Artist: ".$name_artist."<br>"; 

 

Link to comment
https://forums.phpfreaks.com/topic/150885-mkdir-subfolder/#findComment-792847
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
https://forums.phpfreaks.com/topic/150885-mkdir-subfolder/#findComment-792954
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
https://forums.phpfreaks.com/topic/150885-mkdir-subfolder/#findComment-794239
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.