blueman378 Posted September 27, 2007 Share Posted September 27, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/70919-solved-delete-function-prob-really-simple/ Share on other sites More sharing options...
rarebit Posted September 27, 2007 Share Posted September 27, 2007 Each time it returns: ... delete_directory($dirname.'/'.$file); rmdir($dirname.'/'.$file); ... Quote Link to comment https://forums.phpfreaks.com/topic/70919-solved-delete-function-prob-really-simple/#findComment-356516 Share on other sites More sharing options...
blueman378 Posted September 27, 2007 Author Share Posted September 27, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/70919-solved-delete-function-prob-really-simple/#findComment-356527 Share on other sites More sharing options...
blueman378 Posted September 27, 2007 Author Share Posted September 27, 2007 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!"; Quote Link to comment https://forums.phpfreaks.com/topic/70919-solved-delete-function-prob-really-simple/#findComment-356545 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.