Created
September 9, 2015 18:26
-
-
Save sanjaybhowmick/ae379032ce11f8ca3fb7 to your computer and use it in GitHub Desktop.
Destroy all the files in a directory
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 | |
$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