Automated Build Hash updates
All checks were successful
Generate Build Info / build-info (push) Successful in 1s

This commit is contained in:
carpentryplus25
2026-03-05 10:30:37 -05:00
parent 7de33d80f8
commit 9b408542af
2 changed files with 259 additions and 53 deletions

View File

@@ -321,51 +321,56 @@ add_action('admin_post_dapper_backup_dl', 'dapper_handle_backup_download');
function dapper_handle_backup_download() {
if (!current_user_can('manage_options')) {
wp_die('Access denied.');
wp_die('Access denied.', 403);
}
$file = isset($_GET['f']) ? basename($_GET['f']) : '';
$file = isset($_GET['f']) ? basename($_GET['f']) : '';
$folder = isset($_GET['folder']) ? basename($_GET['folder']) : '';
$nonce = $_GET['_wpnonce'] ?? '';
if (!wp_verify_nonce($nonce, 'dapper_dl_' . md5($file))) {
wp_die('Security check failed.');
wp_die('Security check failed.', 403);
}
$path = DAPPER_BACKUP_BASE_DIR . '/' . $folder . '/' . $file;
if (!file_exists($path) || !is_readable($path)) {
wp_die('File not found or inaccessible.');
wp_die('File not found or not readable.', 404);
}
// Disable output buffering & compression for large files
if (ob_get_level()) ob_end_clean();
header_remove('Content-Encoding'); // Prevent gzip
// Kill all output buffering
while (ob_get_level() > 0) {
ob_end_clean();
}
// Proper headers for binary download
// Turn off compression
if (function_exists('apache_setenv')) {
@apache_setenv('no-gzip', 1);
}
@ini_set('zlib.output_compression', 'Off');
// Headers
header('Content-Description: File Transfer');
header('Content-Type: application/zip'); // Force zip type
header('Content-Disposition: attachment; filename="' . $file . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="' . $file . '";');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
// Chunked output to avoid memory issues
header('Content-Length: ' . filesize($path));
// Stream file in 1 MB chunks
$chunk_size = 1024 * 1024; // 1 MB
$handle = fopen($path, 'rb');
// Chunked read — very memory efficient
$chunk = 1 * 1024 * 1024; // 1 MB
$handle = @fopen($path, 'rb');
if ($handle === false) {
wp_die('Failed to open file for reading.');
wp_die('Cannot open file for reading.');
}
while (!feof($handle)) {
echo fread($handle, $chunk_size);
flush(); // Send chunk immediately
echo @fread($handle, $chunk);
flush();
if (connection_aborted()) break;
}
fclose($handle);
@fclose($handle);
exit;
}