// http://php.net/manual/ru/function.rmdir.php#115598
// http://stackoverflow.com/questions/9262622/set-permissions-for-all-files-and-folders-recursively
if (PHP_OS === 'Windows') {
exec("rd /s /q {$path}");
} else {
exec("rm -rf {$path}");
}1
exec ("find {$path} -type d -exec chmod 0750 {} +");
exec ("find {$path} -type f -exec chmod 0644 {} +");