envexlabs Posted September 9, 2008 Share Posted September 9, 2008 Hey, I found this loop on the internet, but it's seems to be deleting the whole folder, not the contents. any insight? <?php /** * Delete a file, or a folder and its contents * * @author Aidan Lister <[email protected]> * @version 1.0.2 * @param string $dirname Directory to delete * @return bool Returns TRUE on success, FALSE on failure */ $tmpdir = $_SERVER['DOCUMENT_ROOT'].'/uploads/tmp/'; function rmdirr($dirname) { // Sanity check if (!file_exists($dirname)) { return false; } // Simple delete for a file if (is_file($dirname)) { return unlink($dirname); } // Loop through the folder $dir = dir($dirname); while (false !== $entry = $dir->read()) { // Skip pointers if ($entry == '.' || $entry == '..') { continue; } // Recurse rmdirr("$dirname/$entry"); } // Clean up $dir->close(); return rmdir($dirname); } rmdirr($tmpdir); ?> Link to comment https://forums.phpfreaks.com/topic/123500-loop-deleting-folder-not-contents/ Share on other sites More sharing options...
BlueSkyIS Posted September 9, 2008 Share Posted September 9, 2008 change this: return rmdir($dirname); to this: return true; Link to comment https://forums.phpfreaks.com/topic/123500-loop-deleting-folder-not-contents/#findComment-637814 Share on other sites More sharing options...
envexlabs Posted September 9, 2008 Author Share Posted September 9, 2008 It still seems to be deleting the whole folder. Link to comment https://forums.phpfreaks.com/topic/123500-loop-deleting-folder-not-contents/#findComment-637817 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.