I have some problem with deleting files and folders. I have a script that
deletes the files and folders inside another folder. Here it is:
<?php
$centre_id = 16;
if(!($result11 = mysql_query("SELECT ct_centre_id, ct_centre_name from ct_centre WHERE ct_centre_id = '$centre_id'", $con)))
{
Error(sprintf("Internal Error %d:%s\n",mysql_errno(),mysql_error()));
exit();
}
$row11 = mysql_fetch_array($result11);
$centre_id = $row11["ct_centre_id"];
$centre_name = $row11["ct_centre_name"];
if(!($result12 = mysql_query("SELECT student_id from ct_centre_coaches WHERE ct_centre_id = '$centre_id'", $con)))
{
Error(sprintf("Internal Error %d:%s\n",mysql_errno(),mysql_error()));
exit();
}
$num_results = mysql_num_rows($result12);
$count = 0;
$id= 0;
for ($i=0; $i<$num_results; $i++)
{
$row12 = mysql_fetch_array($result12);
$coach_id = $row12["student_id"];
if(!($result13 = mysql_query("SELECT ct_cdc_deliv_topic_id from ct_cdc_deliv_topic WHERE ct_centre_id = '$centre_id'", $con)))
{
Error(sprintf("Internal Error %d:%s\n",mysql_errno(),mysql_error()));
exit();
}
// Delete entries from deliverable tables.
while($row13 = mysql_fetch_array($result13))
{
$ct_topic_id = $row13["ct_cdc_deliv_topic_id"];
$center_path = "".$cdc_path."/centre".$centre_id."";
$dir2remove = "".$cdc_path."/centre".$centre_id."/coach".$coach_id."/topic".$ct_topic_id."/version".$version."/";
if ($dir = @opendir("$dir2remove"))
{
while (($file = readdir($dir)) != false)
{
if (!($file=="." || $file==".."))
{
chdir($center_path."/coach".$coach_id."/topic".$ct_topic_id."/version".$version."/");
unlink($center_path."/coach".$coach_id."/topic".$ct_topic_id."/version".$version."/".$file."");
chdir($center_path."/coach".$coach_id."/topic".$ct_topic_id."/");
unlink($center_path."/coach".$coach_id."/topic".$ct_topic_id."/".$file."");
chdir($center_path."/coach".$coach_id."/");
unlink($center_path."/coach".$coach_id."/".$file.""); // ??
chdir($center_path."/");
unlink($center_path."/".$file.""); // ??
}
} //close while
closedir($dir);
rmdir($center_path."/coach".$coach_id."/topic".$ct_topic_id."/version".$version."/");
rmdir($center_path."/coach".$coach_id."/topic".$ct_topic_id."/");
rmdir($center_path."/coach".$coach_id."/"); // ??
rmdir($center_path."/"); // ??
}
}
$stat = "center has been deleted";
}
?>
So, when i run it , it actually works and deletes the stuff, but at the same time it gives the following kind of errors:
Warning: Unlink failed (No such file or directory) in c:.....\script.php on line 71
Warning: RmDir failed (Permission denied) in c:...\script.php on line 79
for lines I marked in the code with "??" sign.
Can someone tell what is the problem ?