Jump to content

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!";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.