Hi,

can somebody help me how can I delete non-empty directory by PHP3 command (rmdir) or another command ?

Thanks

Jiri Eger
jiri@eger.cz

    Jiri,

    Try this:
    system(rmdir -rf dir);

    Hope this helps,
    [ John

      Hi,

      thanks for help, but when I use your line with modify dir, then I get message:

      Parse error: parse error in /usr/local/httpd/htdocs/www/nastenky/user/user_del.phtml on line 92

      Is it correct for PHP3 ?

      Thanks

      Jiri Eger
      jiri@eger.cz

        2 months later

        Hi John Barker

        When you use the system() function to remove directory with contents in php, don't you need to specify the path??? If yes, how? can you give an exampel code? I did not try your line of code becuase I feared that everything will get deleted. please help on this.

          2 years later

          Jiri,

          Here is the entire code you can use to delete the dir:

          <?php
          function delete($file) {
          chmod($file,0777);
          if (is_dir($file)) {
          $handle = opendir($file);
          while($filename = readdir($handle)) {
          if ($filename != "." && $filename != "..")
          {
          delete($file."/".$filename);
          }
          }
          closedir($handle);
          rmdir($file);
          } else {
          unlink($file);
          }
          }
          delete("dir_name");
          ?>

          At the bottum where it says "delete("dir_name");" just change the word dir_name to the dir name. Just put this PHP file in the above dir.

          Hope this helps.

          David

            Write a Reply...