我有一张表,其中包含我希望删除内容的所有文件夹的名称。现在我有一个脚本,它将删除我设置的文件夹的全部内容。现在我虽然可以将该代码放在一个while循环中,它会删除所有文件夹的内容。但是,我得到一个错误。这是代码,错误在底部,出了什么问题,我该如何解决?
$query = "SELECT * FROM gemeentes";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
$gemeente1 = str_replace(" ","",$row['gemeente']);
$gemeente2 = strtolower($gemeente1);
$gemeente3 = str_replace("(","-",$gemeente2);
$gemeente4 = str_replace(")","",$gemeente3);
$gemeente5 = str_replace(",","",$gemeente4);
if(isset($_POST['GO'])) {
$directory = "../subdomains/".$gemeente5."/httpdocs/";
echo $directory;
define('PATH', $directory);
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("couldn't delete $dir$file<br />");
}
else
unlink($dir.$file) or DIE("couldn't delete $dir$file<br />");
}
}
closedir($mydir);
}
destroy(PATH);
echo 'all done.';
}
}
第一个删除恢复正常,第二个不再起作用:
../subdomains/aaenhunze/httpdocs/all done.../subdomains/aalburg/httpdocs/
Fatal error: Cannot redeclare destroy() (previously declared in /vhosts/url.nl/httpdocs/deletecontent.php:50) in /vhosts/url.nl/httpdocs/deletecontent.php on line 50