Created
July 13, 2013 16:41
-
-
Save psdtohtml5/5991280 to your computer and use it in GitHub Desktop.
PHP : Recursively delete files and folders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//define('UPLOADFILES', dirname(dirname(__FILE__)) . '/sixpoints'); | |
function recursiveDelete($path) { | |
// if (strpos($path, UPLOADFILES) === false) { | |
// exit('Trying to remove from wrong path to uploadfiles!'); | |
// } | |
if (is_file($path)) { | |
return unlink($path); | |
} elseif ( is_dir($path) ){ | |
$objects = scandir($path); | |
foreach ($objects as $object) { | |
if($object != '.' && $object != '..'){ | |
recursiveDelete($path . '/' . $object); | |
} | |
} | |
reset($objects); | |
return rmdir($path); | |
} | |
} | |
recursiveDelete('../../sixpoints/wp-content'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment