Woodburn2006 Posted September 21, 2007 Share Posted September 21, 2007 is there any way of deleteing a folder and all of its contents using PHP? Quote Link to comment https://forums.phpfreaks.com/topic/70197-delete-folder-and-its-contents/ Share on other sites More sharing options...
recklessgeneral Posted September 21, 2007 Share Posted September 21, 2007 Hi, A combination of rmdir and unlink should do the job. See the discussion on the php.net website here: http://www.php.net/manual/en/function.rmdir.php Cheers, Darren. Quote Link to comment https://forums.phpfreaks.com/topic/70197-delete-folder-and-its-contents/#findComment-352575 Share on other sites More sharing options...
Gmunky Posted September 21, 2007 Share Posted September 21, 2007 $filespath="folder/*"; //path of files to be deleted $folder="folder"; //path of folder to be deleted foreach (glob($filepath) as $filename) { unlink($filename); } rmdir($folder); Quote Link to comment https://forums.phpfreaks.com/topic/70197-delete-folder-and-its-contents/#findComment-352580 Share on other sites More sharing options...
recklessgeneral Posted September 21, 2007 Share Posted September 21, 2007 $filespath="folder/*"; //path of files to be deleted $folder="folder"; //path of folder to be deleted foreach (glob($filepath) as $filename) { unlink($filename); } rmdir($folder); Will this only work if the $folder path doesn't contain any directories? Quote Link to comment https://forums.phpfreaks.com/topic/70197-delete-folder-and-its-contents/#findComment-352596 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.