You need to be the owner or at least have the rwx permission to the directory under which you want to delete the subdirectories and files. Try this thing by unix promt,telnet or ftp, change the chmod of the directory and the subdirectories to rwx (i.e, read write and execute). The code will be like this if you want to delete the subdirectories(which have no further subdirectories) and files:
<?php
$handle=opendir('.');
while (false!==($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$occur=strstr($file,'.');
$filetime=filemtime($file);
$latesttime=time();
$dtime=$latesttime-$filetime;
if($occur!="")
{
if($dtime>=604800)
{
unlink($file);
}
}
else
{
$handle2=opendir($file);
while (false!==($file2 = readdir($handle2))) {
if ($file2 != "." && $file2 != "..") {
$occur2=strstr($file2,'.');
if($occur2!="" && $dtime>=604800)
{
unlink($file.'/'.$file2);
}
}
}
closedir($handle2);
rmdir($file);
}
}
}
closedir($handle);
?>