Skip to content

Instantly share code, notes, and snippets.

@blbwd
Created Sep 9, 2015
Embed
What would you like to do?
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