how to use mkdir in php

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    how to use mkdir in php

    i m trying to check and make muliple dir in a single command by mkdir command bt nt get success, is there any alternative or how to use it. . Ex- file/a/b/c i want to if there a,b or c dir present if nt create which is nt present. If a, present bt b,c nt then create b and c both.. Pls share if u knw the solution .. At present i m using loop to do this .

    #2
    Make an array with a b c names, do foreach() loop with if() and is_dir(), and if it returns true set continue; else mkdir().
    Check this for start: http://coding-talk.com/f46/source-co...html#post97296
    <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

    Comment


      #3
      i m already using while loop in my script bt i want to do it without loop.. I google this bt not find appriate solution 4 php script.

      Comment


        #4
        It goes anyway, both are needed.
        <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

        Comment


          #5
          PHP Code:
          <?php
          $path
          ="download/";
          $dirname="muzic";
          $final="$path$dirname";
          if (!
          mkdir($final0777true)) {
              die(
          'Failed to create folders...');
          }
          else
          {
          mkdir("$final"0777true);
          chmod("$final"0777);
          echo
          "Folder Created Successfully!!";
          }
          ?>

          Comment


            #6
            Simpler one
            Code:
               function makedir ($pathname ){
                  if(mkdir ($pathname,0700,true)){
                  return true ;
                  }else{
                  return false;
                  }
               }
            pass multiple path :D it will create for u :D

            Comment


              #7
              arbind and sushant thanks 4 ur reply i will try these codes, hope it works, bt my main point is to make to 2 or 3 directory at once.. Like /dir1/dir2/dir3 in a single command i used mkdir -p also got error.

              Comment


                #8
                try this
                PHP Code:
                <?php
                // Desired folder structure
                $structure './depth1/depth2/depth3/';

                // To create the nested structure, the $recursive parameter 
                // to mkdir() must be specified.

                if (!mkdir($structure0true)) {
                    die(
                'Failed to create folders...');
                }

                // ...
                ?>
                Added after 6 minutes:

                Try this 101% working
                PHP Code:
                <?php
                $foldername
                ="hello";
                mkdir("$foldername"0777);  // create folder 

                chmod"$foldername"0777 ); // chmod folder to 0777

                mkdir("$foldername/pics"0777); // create folder 

                chmod("$foldername/pics"0777 ); // chmod folder to 0777

                echo"Sucessfully created";

                ?>
                Last edited by arbind004; 18.06.12, 09:44.

                Comment

                Working...
                X