I am using PHP to move the contents of a images subfolder
GalleryName/images/
into another folder. After the move, I need to del
This is the recursive function I've created/modifed and that finally seems to be working. Hopefully there isn't anything too dangerous in it.
function destroy_dir($dir) {
if (!is_dir($dir) || is_link($dir)) return unlink($dir);
foreach (scandir($dir) as $file) {
if ($file == '.' || $file == '..') continue;
if (!destroy_dir($dir . DIRECTORY_SEPARATOR . $file)) {
chmod($dir . DIRECTORY_SEPARATOR . $file, 0777);
if (!destroy_dir($dir . DIRECTORY_SEPARATOR . $file)) return false;
};
}
return rmdir($dir);
}