isDir() && !$item->isLink()) {
self::rmdir($item->getPathname());
} else {
self::delete($item->getPathname());
}
}
self::rmdir($dir);
}
/**
* Send a file to the browser in 1 MB pieces (backups can be larger than memory_limit).
*/
public static function output($path) {
$handle = self::open($path, 'rb');
if (!$handle) {
return false;
}
while (!feof($handle)) {
echo fread($handle, MB_IN_BYTES); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- binary file download.
flush();
}
return self::close($handle);
}
/**
* Create a folder that must never be reachable from the web.
*/
public static function protect_dir($dir) {
if (!is_dir($dir)) {
wp_mkdir_p($dir);
}
file_put_contents($dir . '/.htaccess', "# Generated by EnMigrate Pro\n\n Require all denied\n\n\n Deny from all\n\nOptions -Indexes\n");
file_put_contents($dir . '/web.config', "\n\n");
if (!file_exists($dir . '/index.php')) {
file_put_contents($dir . '/index.php', "