I need to be able to make directories with sub directories...
mkdir("$upload_dir/images",0777);

for some reason the above does not work, I'm on Apache...

This does work...
mkdir("$upload_dir",0700);
mkdir("$upload_dir/images",0700);

Is something wrong with the first statement?

Also if the directory(ies) are already created I get an error... I think I need to have if statements in place to see if any are already created. How do I do it?

    Sorry the permissions are all 0777...

    The first message should have read like this...

    I need to be able to make directories with sub directories...
    mkdir("$upload_dir/images",0777);

    for some reason the above does not work, I'm on Apache...

    This does work...
    mkdir("$upload_dir",0777);
    mkdir("$upload_dir/images",0777);

    Is something wrong with the first statement?

    Also if the directory(ies) are already created I get an error... I think I need to have if statements in place to see if any are already created. How do I do it?

      mkdir makes a directory, not a directory tree.
      You'll have to make each directory seperately.

      something like (UNTESTED):

      split the path up into its subdirectories

      $aDirs=split("/",$path);

      #Get the first directory to make. Why do this sperately? because I will append the other directories using a slash, and I don't want a slash for the first directory
      $sDirToMake=$aDirs[0];

      Make it

      mkdir ($sDirToMake);

      loop through the rest of the directories

      for ($t=1;$t<count($aDirs);$t++)
      {

      Append a slash and the next directory

      $sDirToMake.="/".$aDirs[$t];

      #Make it
      mkdir ($sDirToMake);

      continue loop

      };

        DUDE!

        I don't know how you come up with this...

        WORKS GREAT! WAY WAY COOL!!!

        This form is being used over and over.

        What if the Directories are already created???

        I get a file exist error...

        Thanks Vincent once again... WOW!

          btw the only thing I had to add just for the record is the permissions 0777

          mkdir ($sDirToMake,0777);

          on both mkdir s

          otherwise it worked perfect...

            giggle well at least there was one mistake in there.
            I was getting worried that I was able to write code off the top of my head that actually worked :-)

            Indeed the script needs error-checking (the thing that I am always going on about)

            Here's an improved version:

            function makedir($sDir)
            {
            echo "Checking $sDir ... ";
            if (file_exists($sDir))
            {
            if (is_dir($sDir))
            {
            echo "$sDirToMake already exists\n";
            return 1;
            }
            else
            {
            echo "$sDirToMake is a file\n";
            return 0;
            };
            }
            else
            {
            mkdir ($sDir,0777);
            return 1;
            }
            };

            $path="/tmp/a/b/c";

            split the path up into its subdirectories

            If the path begins with a slash, skip it and prepend the slash to the first subdir

            if($path[0]!="/")
            {
            $aDirs=split("/",$path);
            }
            else
            {
            $aDirs=split("/",substr($path,1));
            $aDirs[0]="/".$aDirs[0];
            };

            Get the first directory to make.

            Why do this sperately? because I will append the other

            directories using a slash, and I don't want a slash for the first directory

            $sDirToMake=$aDirs[0];

            Make it

            if (!makedir($sDirToMake))
            {
            echo "giving up.\n";
            exit;
            };

            loop through the rest of the directories

            for ($t=1;$t<count($aDirs);$t++)
            {

            Append a slash and the next directory

            $sDirToMake.="/".$aDirs[$t];

            #Make it or die trying
            if (!makedir($sDirToMake))
            {
            echo "giving up.\n";
            exit;
            };

            continue loop

            };
            exit;

              ARGH...

              This one did not work to well for me...

              Due to time constraints on the project I'm going to have to come back to this one and ask you about it later if that's cool...

              But atleast I got the making of the directory w/ sub-directorieds correct. <big grin>

              Many Thanks Vinny... Hope you had a Happy New Year!

                a month later

                If this problem is on win, it is logical, since the OS win9X (dos-based) doesn't support creating subdirectories at once. Trie the command-prompt:
                md thisdirectorydoesnexist\thisneither

                it wouldn't work, since windows will be looking for the directory thisdirectorydoesnexist and it (so it says:-) doesnt exist

                good luck

                  Nah it's UNIX...

                  Windows has never been a scalable solution for me personally...

                  I've actually got a temp solution, though...
                  Thanks for responding...

                    Write a Reply...