I think it's mainly a safety precaution. So as you don't remove a directory with files you may need. The rm command on linux will by default not delete a directory empty or not empty. It requires that you supply it an agrument to confirm you want to delete the directory. If the directory is not empty you must also spply an argument which confirms it should delete its contents; sub directories and files. You can easily create a function in PHP to clear a directory before deleting it.
function rmdir_recursive ($path) {
if (!$roothwnd = opendir($path)) {
echo ("Error opening directory $path during directory deletion\n");
return false;
}
while ($file = readdir($roothwnd)) {
$fpath = (substr ($path, -1) == '/')?($path . $file):($path . '/' . $file);
if (is_dir ($fpath)){
if ($file == '..' || $file == '.') continue;
if (!cleardir ($fpath)) return false;
} else {
if (!@unlink ($fpath)) {
echo ("Error deleting $fpath during directory deletion\n");
return false;
}
}
}
closedir ($roothwnd);
if (!@rmdir ($path)) {
echo ("Error removing directory $path during directory deletion\n");
return false;
}
return true;
}
This function deletes all files and sub directories and finally the supplied directory. If it encounters a subdirectory it just calls itself again with the path of the sub directory. If there is an error deleting any file or sub directory the function will fail and return false.