i would not recommend that as a solution,
why don't you secure the script instead ?
anyway just for the fun of it here is a function that will delete a folder
function deleteAll($directory, $empty = false) {
$t= time(); // you can also use it to delete old files by subtracting from this
if(substr($directory,-1) == "/") {
$directory = substr($directory,0,-1);
}
if(!file_exists($directory) || !is_dir($directory)) {
return false;
} elseif(!is_readable($directory)) {
return false;
} else {
$directoryHandle = opendir($directory);
while ($contents = readdir($directoryHandle)) {
if($contents != '.' && $contents != '..') {
if(filemtime($directory . "/" . $contents) < $t) {
$path = $directory . "/" . $contents;
if(is_dir($path)) {
@deleteAll($path);
} else {
@unlink($path);
}
}
}
}
closedir($directoryHandle);
if($empty == false) {
if(!@rmdir($directory)) {
return false;
}
}
return true;
}
}
(!) be careful when you use it it will DELETE everything you can call it like this deleteAll(".", true);
but this is not a solution look into securing your script
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…