Delete a folder...It worked and now it doesn't

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • webandwe
    New Member
    • Oct 2006
    • 142

    Delete a folder...It worked and now it doesn't

    Hi, Please help here

    I made this delete script to delete a folder on the hosting server and the files within.

    It worked a month ago but now it does not work...

    [PHP]
    <?php

    $dfolder = $_POST['dfolder'];

    $myFile = "$dfolder";
    rmdir($myFile);

    ?>
    [/PHP]

    It worked on my local server as well but also it aint working on it.

    I tried unlink, unset, FTP_delete and the one that is suppose to work rmdir. I even set the permission but the permission are right.

    Can some please tell me why it worked and now does not want to work!
  • dafodil
    Contributor
    • Jul 2007
    • 389

    #2
    Originally posted by webandwe
    Hi, Please help here

    I made this delete script to delete a folder on the hosting server and the files within.

    It worked a month ago but now it does not work...

    [PHP]
    <?php

    $dfolder = $_POST['dfolder'];

    $myFile = "$dfolder";
    rmdir($myFile);

    ?>
    [/PHP]



    It worked on my local server as well but also it aint working on it.

    I tried unlink, unset, FTP_delete and the one that is suppose to work rmdir. I even set the permission but the permission are right.

    Can some please tell me why it worked and now does not want to work!
    Check if you have the existing folder before you delete....
    Is there any errors? If yes please show the error....

    Comment

    • webandwe
      New Member
      • Oct 2006
      • 142

      #3
      Hi, no it is just a folder with images it it.

      The error I get is.

      The directory is not empty...It always deleted the files in the folder and then the folder but now I just get that error message.

      Regards

      Comment

      • epots9
        Recognized Expert Top Contributor
        • May 2007
        • 1352

        #4
        give this a try http://us3.php.net/manual/en/function.exec.php

        [PHP]
        echo exec('rm - r '.$myFile);
        [/PHP]

        Comment

        • nomad
          Recognized Expert Contributor
          • Mar 2007
          • 664

          #5
          Originally posted by webandwe
          Hi, Please help here

          I made this delete script to delete a folder on the hosting server and the files within.

          It worked a month ago but now it does not work...

          [PHP]
          <?php

          $dfolder = $_POST['dfolder'];

          $myFile = "$dfolder";
          rmdir($myFile);

          ?>
          [/PHP]

          It worked on my local server as well but also it aint working on it.

          I tried unlink, unset, FTP_delete and the one that is suppose to work rmdir. I even set the permission but the permission are right.

          Can some please tell me why it worked and now does not want to work!
          webandwe
          Two thing you can do.
          Make sure you have the right dir. and that the folder is spelled the same as your code.
          or
          make a new folder and then change your code dfolder to the new folder name.

          nomad

          Comment

          • mwasif
            Recognized Expert Contributor
            • Jul 2006
            • 802

            #6
            PHP manual says The directory must be empty. Checkout the manual rmdir().

            Comment

            • Motoma
              Recognized Expert Specialist
              • Jan 2007
              • 3236

              #7
              This code may help you out:

              [code=php]
              <?
              /*************** *************** *************** *************** ********
              rm.php
              *************** *************** *************** *************** ********/
              /*
              Deletes a file or directory
              Usage: rm("filename") ;
              rm("directory") ;
              rm("directory/*");
              rm("*.txt");
              */
              function rm($fileglob)
              {
              if (is_string($fil eglob))
              {
              if (is_file($fileg lob)) return unlink($fileglo b);
              else if (is_dir($filegl ob))
              {
              $ok = rm("$fileglob/*");
              if (! $ok) return false;
              return rmdir($fileglob );
              } else {
              $matching = glob($fileglob) ;
              if ($matching === false)
              {
              trigger_error(s printf('No files match supplied glob %s', $fileglob), E_USER_WARNING) ;
              return false;
              }
              $rcs = array_map('rm', $matching);
              if (in_array(false , $rcs)) return false;
              }
              }
              else if (is_array($file glob))
              {
              $rcs = array_map('rm', $fileglob);
              if (in_array(false , $rcs)) return false;
              } else {
              trigger_error(' Param #1 must be filename or glob pattern, or array of filenames or glob patterns', E_USER_ERROR);
              return false;
              }
              return true;
              }
              [/code]

              Comment

              Working...