Jump to content

[SOLVED] delete function prob really simple


blueman378

Recommended Posts

ok heres my code

ffunction  delete_directory($dirname)  {
        if  (is_dir($dirname))
                $dir_handle  =  opendir($dirname);
        if  (!$dir_handle)
                return  false;
        while($file  =  readdir($dir_handle))  {
                if  ($file  !=  "."  &&  $file  !=  "..")  {
                        if  (!is_dir($dirname."/".$file))
                                unlink($dirname."/".$file);
                        else
                                delete_directory($dirname.'/'.$file);                       
                }
        }
        closedir($dir_handle);
        rmdir($dirname);
        return  true;
} 

 

now my problem is i cant see what part i would declare the directory to be deleted,

while i was typing this i ust thought maybe i have to state it in another variable?

 

ust asking

thanks

i dont quite get what you mean by that.

 

what the code is meant to do is:

it takes a directory as an argument and then uses functional recursion to delete all files and folders within, and then finally removes the directory. Nice and quick, too.

 

 

so heres my code

/* Delete user from database */
      else{
         $q = "DELETE FROM ".TBL_USERS." WHERE username = '$subuser'";
         $database->query($q);
	 $dirname = '/home/vol2/byethost13.com/b13_1013561/mydoodle.byethost13.com/htdocs/users/$subuser';
	 function  delete_directory($dirname)  {
        if  (is_dir($dirname))
                $dir_handle  =  opendir($dirname);
        if  (!$dir_handle)
                return  false;
        while($file  =  readdir($dir_handle))  {
                if  ($file  !=  "."  &&  $file  !=  "..")  {
                        if  (!is_dir($dirname."/".$file))
                                unlink($dirname."/".$file);
                        else
                                delete_directory($dirname.'/'.$file);                       
                }
        }
        closedir($dir_handle);
        rmdir($dirname);
        return  true;
} 
         header("Location: ".$session->referrer);
      }

 

now the problem is the code is giving out no errors it sucessfully deletes the user from the database however it leaves the folder behind and i have no idea why because it leaves no errors

please people i really need help with this

 

my code now is

if ($handle = opendir('/home/vol2/byethost13.com/b13_1013561/mydoodle.byethost13.com/htdocs/users/$subuser')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && is_file($file)) {
print $file; 
}
}
closedir($handle);
} 
rmdir("/home/vol2/byethost13.com/b13_1013561/mydoodle.byethost13.com/htdocs/users/$subuser");
echo"folder $subuser deleted!";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.