function emptyDir($path) { if ($handle = OPENDIR($path)) { while (FALSE !== ($file = READDIR($handle))) { if ($file != "." && $file != "..") { if (IS_FILE($path . "/" . $file)) { if (UNLINK($path . "/" . $file)) { $debugStr = true; } } } } } return $debugStr; }
private function emptyDir($path) { // init the debug string $debugStr = ''; $debugStr .= "Deleting Contents Of: $path<br /><br />"; // parse the folder IF ($handle = OPENDIR($path)) { WHILE (FALSE !== ($file = READDIR($handle))) { IF ($file != "." && $file != "..") { // If it's a file, delete it IF (IS_FILE($path . "/" . $file)) { IF (UNLINK($path . "/" . $file)) { $debugStr .= "Deleted File: " . $file . "<br />"; } } ELSE { // It's a directory... // crawl through the directory and delete the contents IF ($handle2 = OPENDIR($path . "/" . $file)) { WHILE (FALSE !== ($file2 = READDIR($handle2))) { IF ($file2 != "." && $file2 != "..") { IF (UNLINK($path . "/" . $file . "/" . $file2)) { $debugStr .= "Deleted File: $file/$file2<br />"; } } } } IF (RMDIR($path . "/" . $file)) { $debugStr .= "Directory: " . $file . "<br />"; } } } } } return $debugStr; }