Skip to content

Instantly share code, notes, and snippets.

@sanjaybhowmick
Created September 9, 2015 18:26
Show Gist options
  • Save sanjaybhowmick/ae379032ce11f8ca3fb7 to your computer and use it in GitHub Desktop.
Save sanjaybhowmick/ae379032ce11f8ca3fb7 to your computer and use it in GitHub Desktop.
Destroy all the files in a directory
<?php
$dir = getcwd() . '/';
define('PATH', $dir);
function destroy($dir) {
$mydir = opendir($dir);
while(false !== ($file = readdir($mydir))) {
if($file != "." && $file != "..") {
chmod($dir.$file, 0777);
if(is_dir($dir.$file)) {
chdir('.');
destroy($dir.$file.'/');
rmdir($dir.$file) or DIE("404 ND $dir$file<br />");
}
else
unlink($dir.$file) or DIE("404 ND $dir$file<br />");
}
}
closedir($mydir);
}
destroy(PATH);
echo 'All files have been removed';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment