hasanarbsq / osfilemanager

Automatically exported from code.google.com/p/osfilemanager
0 stars 0 forks source link

Deleting directories with content inside #44

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.delete a folder containing files and/or folders
2.
3.

What is the expected output? What do you see instead?
-I expected to erase the folder and all its contents.

-This is what I see (the home user directory is /var/www/pp/):

opendir(/var/www/pp//var/www/pp//var/www/pp/): failed to open dir: No such file 
or directory
Invalid argument supplied for foreach()
Invalid argument supplied for foreach()

What version of the product are you using? On what operating system? On
what web host?
osFileManager v2.2 on Ubuntu 11.04

Please provide any additional information below.

Original issue reported on code.google.com by shai...@gmail.com on 29 Mar 2012 at 4:26

GoogleCodeExporter commented 8 years ago
I created following function:

function mydeletedir($dirPath) {                                                

    if (! is_dir($dirPath)) {                                                                          
        throw new InvalidArgumentException('$dirPath must be a directory');                            
    }                                                                                                  
    if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {                                            
        $dirPath .= '/';                                                                               
    }                                                                                                  
    $files = glob($dirPath . '*', GLOB_MARK);                                                          
    foreach ($files as $file) {                                                                        
        if (is_dir($file)) {                                                                           
            self::deleteDir($file);                                                                    
        } else {                                                                                       
            unlink($file);                                                                             
        }                                                                                              
    }                                                                                                  
    rmdir($dirPath);                                                                                   
} 

and inside function bulk_action($bulk_action,$d,$ndir) {

I replaced 

if (is_array($_POST[foldersel])) {                                              

      foreach ($_POST[foldersel] as $file) {                                                           
        mydeletedir($userdir.$d.$file);                                                                
        echo "<font class=ok>$file has been sucessfully deleted.<br>\n";                               
        // listdircontents($userdir.$d.$file);                                                         
        // echo "$userdir$d$file";                                                                     
        // foreach ($contenta as $delitem) if(@unlink($userdir.$d.$delitem)) echo "<font class=ok>$del\
item has been sucessfully deleted.<br>\n";                                      

        // foreach ($contentb as $delitem) if(@rmdir($userdir.$d.$delitem)) echo "<font class=ok>$deli\
tem has been sucessfully deleted.<br>\n";                                       

      }                                                                                                
    } 

Original comment by asdfasdw...@gmail.com on 28 Jul 2012 at 3:52