delete folder

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anfetienne
    Contributor
    • Feb 2009
    • 424

    delete folder

    hi ive got a folder on my server which is created by apache and the only way to delete it is with server coding.

    can someone tell me a way to delete that folder including all files and folders within it?
  • Ciary
    Recognized Expert New Member
    • Apr 2009
    • 247

    #2
    Code:
    foreach(glob($mydir."/*") as $val){
       if(is_dir($val)){
          foreach(glob($val."/*") as $v){
             if(is_dir($v)){
                ...       //you'll need to do this a few times to be sure all subfolders will be deleted
             }else{
                unlink($v);
             }
          }
          rmdir($mydir);
       }else{
          unlink($val);
       }
    }
    rmdir($mydir);

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      Originally posted by anfetienne
      hi ive got a folder on my server which is created by apache and the only way to delete it is with server coding.
      out of interest, what causes that? and deleting via FTP didn't work (permissions?)

      Originally posted by anfetienne
      can someone tell me a way to delete that folder including all files and folders within it?
      if you have a shell prompt for your server and sufficient permissions, you may execute the appropriate commands there (e.g. rmdir -r (*nix))

      Comment

      • anfetienne
        Contributor
        • Feb 2009
        • 424

        #4
        basically if you create folders with php code & apache you cant delete via ftp.....because the permissions set are through and for apache.....even if its 0777 you cant delete it

        i had to consult my hosting company and this is what they told me

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          ah, ok, good to know. maybe shell_exec() can help too.

          Comment

          Working...