Skip to content

Instantly share code, notes, and snippets.

@psdtohtml5
Created July 13, 2013 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psdtohtml5/5991280 to your computer and use it in GitHub Desktop.
Save psdtohtml5/5991280 to your computer and use it in GitHub Desktop.
PHP : Recursively delete files and folders
<?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