Plugin Directory

Changeset 3211352


Ignore:
Timestamp:
12/21/2024 04:09:46 AM (11 months ago)
Author:
seobaked
Message:

Fixed v1.0.2 download error

Location:
seinc-backup
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • seinc-backup/tags/1.0.2/seinc-backup.php

    r3211323 r3211352  
    283283        $files = glob($backup_path . 'wp-backup-*.zip');
    284284        foreach ($files as $file) {
    285             // Get file modification time in GMT
     285            // Get file modification time
    286286            $file_time = filemtime($file);
    287             $gmt_time = gmdate('Y-m-d H:i:s', $file_time);
     287           
     288            // Convert to WordPress timezone
     289            $date_time = new DateTime();
     290            $date_time->setTimestamp($file_time);
     291            $date_time->setTimezone(wp_timezone());
    288292           
    289293            $backups[] = array(
    290294                'name' => basename($file),
    291295                'size' => size_format(filesize($file)),
    292                 'date' => gmdate(get_option('date_format') . ' ' . get_option('time_format'), $file_time)
     296                'date' => wp_date(get_option('date_format') . ' ' . get_option('time_format'), $file_time)
    293297            );
    294298        }
     
    302306    }
    303307
    304     $file = isset($_GET['file']) ? sanitize_file_name(wp_unslash($_GET['file'])) : '';
    305     if (empty($file) || !isset($_GET['_wpnonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wpnonce'])), 'seinc_backup_download_' . $file)) {
    306         wp_die(esc_html__('Invalid request', 'seinc-backup'));
    307     }
    308 
     308    // Verify nonce
     309    if (!isset($_GET['file']) || !wp_verify_nonce($_GET['_wpnonce'], 'seinc_backup_download_' . $_GET['file'])) {
     310        wp_die(esc_html__('Invalid download request', 'seinc-backup'));
     311    }
     312
     313    $file = sanitize_file_name(wp_unslash($_GET['file']));
    309314    $backup_path = seinc_backup_get_path();
    310315    $file_path = trailingslashit($backup_path) . $file;
    311316
    312     if (!file_exists($file_path)) {
    313         wp_die(esc_html__('File not found', 'seinc-backup'));
    314     }
    315 
    316     // Log download attempt
     317    // Initialize WP_Filesystem
     318    require_once(ABSPATH . 'wp-admin/includes/file.php');
     319    WP_Filesystem();
     320    global $wp_filesystem;
     321
     322    // Check if file exists and is readable
     323    if (!$wp_filesystem->exists($file_path)) {
     324        wp_die(esc_html__('Backup file not found', 'seinc-backup'));
     325    }
     326
     327    // Get file size
     328    $file_size = $wp_filesystem->size($file_path);
     329    if ($file_size === false || $file_size === 0) {
     330        wp_die(esc_html__('Invalid backup file', 'seinc-backup'));
     331    }
     332
     333    // Clean any previous output
     334    while (ob_get_level()) {
     335        ob_end_clean();
     336    }
     337
     338    // Set download headers
     339    nocache_headers();
     340    header('Content-Description: File Transfer');
     341    header('Content-Type: application/zip');
     342    header('Content-Disposition: attachment; filename="' . basename($file_path) . '"');
     343    header('Content-Transfer-Encoding: binary');
     344    header('Content-Length: ' . $file_size);
     345    header('Accept-Ranges: bytes');
     346    header('Cache-Control: private');
     347    header('Pragma: private');
     348    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
     349
     350    // Log download start
    317351    global $seinc_backup_logs;
    318352    $seinc_backup_logs->add_log(
     
    321355        $backup_path,
    322356        'info',
    323         'Starting file download'
     357        'Starting backup download'
    324358    );
    325359
    326     // Clean any previous output
    327     if (ob_get_level()) {
    328         ob_end_clean();
    329     }
    330 
    331     // Send appropriate headers
    332     nocache_headers();
    333     header('Content-Type: application/octet-stream');
    334     header('Content-Description: File Transfer');
    335     header('Content-Disposition: attachment; filename="' . esc_attr(basename($file_path)) . '"');
    336     header('Content-Transfer-Encoding: binary');
    337     header('Content-Length: ' . $file_size);
    338     header('Connection: close');
    339 
    340     // Initialize WP_Filesystem
    341     require_once(ABSPATH . 'wp-admin/includes/file.php');
    342     WP_Filesystem();
    343     global $wp_filesystem;
    344 
    345     // Check if file exists and is readable
    346     if (!$wp_filesystem->exists($file_path)) {
    347         // Log error
    348         $seinc_backup_logs->add_log(
    349             'manual_download_error',
    350             $file,
    351             $backup_path,
    352             'error',
    353             'Backup file not found'
    354         );
    355         wp_die(esc_html__('Backup file not found', 'seinc-backup'));
    356     }
    357 
    358     // Get file contents using WP_Filesystem
     360    // Disable time limit for large files
     361    set_time_limit(0);
     362
     363    // Get and output file contents
    359364    $file_contents = $wp_filesystem->get_contents($file_path);
    360     if (false === $file_contents) {
    361         // Log error
     365    if ($file_contents === false) {
     366        // Log download error
    362367        $seinc_backup_logs->add_log(
    363368            'manual_download_error',
     
    382387        'Backup downloaded successfully'
    383388    );
    384     exit();
     389    exit;
    385390}
    386391add_action('admin_post_seinc_backup_download', 'seinc_backup_download');
  • seinc-backup/trunk/seinc-backup.php

    r3211323 r3211352  
    283283        $files = glob($backup_path . 'wp-backup-*.zip');
    284284        foreach ($files as $file) {
    285             // Get file modification time in GMT
     285            // Get file modification time
    286286            $file_time = filemtime($file);
    287             $gmt_time = gmdate('Y-m-d H:i:s', $file_time);
     287           
     288            // Convert to WordPress timezone
     289            $date_time = new DateTime();
     290            $date_time->setTimestamp($file_time);
     291            $date_time->setTimezone(wp_timezone());
    288292           
    289293            $backups[] = array(
    290294                'name' => basename($file),
    291295                'size' => size_format(filesize($file)),
    292                 'date' => gmdate(get_option('date_format') . ' ' . get_option('time_format'), $file_time)
     296                'date' => wp_date(get_option('date_format') . ' ' . get_option('time_format'), $file_time)
    293297            );
    294298        }
     
    302306    }
    303307
    304     $file = isset($_GET['file']) ? sanitize_file_name(wp_unslash($_GET['file'])) : '';
    305     if (empty($file) || !isset($_GET['_wpnonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wpnonce'])), 'seinc_backup_download_' . $file)) {
    306         wp_die(esc_html__('Invalid request', 'seinc-backup'));
    307     }
    308 
     308    // Verify nonce
     309    if (!isset($_GET['file']) || !wp_verify_nonce($_GET['_wpnonce'], 'seinc_backup_download_' . $_GET['file'])) {
     310        wp_die(esc_html__('Invalid download request', 'seinc-backup'));
     311    }
     312
     313    $file = sanitize_file_name(wp_unslash($_GET['file']));
    309314    $backup_path = seinc_backup_get_path();
    310315    $file_path = trailingslashit($backup_path) . $file;
    311316
    312     if (!file_exists($file_path)) {
    313         wp_die(esc_html__('File not found', 'seinc-backup'));
    314     }
    315 
    316     // Log download attempt
     317    // Initialize WP_Filesystem
     318    require_once(ABSPATH . 'wp-admin/includes/file.php');
     319    WP_Filesystem();
     320    global $wp_filesystem;
     321
     322    // Check if file exists and is readable
     323    if (!$wp_filesystem->exists($file_path)) {
     324        wp_die(esc_html__('Backup file not found', 'seinc-backup'));
     325    }
     326
     327    // Get file size
     328    $file_size = $wp_filesystem->size($file_path);
     329    if ($file_size === false || $file_size === 0) {
     330        wp_die(esc_html__('Invalid backup file', 'seinc-backup'));
     331    }
     332
     333    // Clean any previous output
     334    while (ob_get_level()) {
     335        ob_end_clean();
     336    }
     337
     338    // Set download headers
     339    nocache_headers();
     340    header('Content-Description: File Transfer');
     341    header('Content-Type: application/zip');
     342    header('Content-Disposition: attachment; filename="' . basename($file_path) . '"');
     343    header('Content-Transfer-Encoding: binary');
     344    header('Content-Length: ' . $file_size);
     345    header('Accept-Ranges: bytes');
     346    header('Cache-Control: private');
     347    header('Pragma: private');
     348    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
     349
     350    // Log download start
    317351    global $seinc_backup_logs;
    318352    $seinc_backup_logs->add_log(
     
    321355        $backup_path,
    322356        'info',
    323         'Starting file download'
     357        'Starting backup download'
    324358    );
    325359
    326     // Clean any previous output
    327     if (ob_get_level()) {
    328         ob_end_clean();
    329     }
    330 
    331     // Send appropriate headers
    332     nocache_headers();
    333     header('Content-Type: application/octet-stream');
    334     header('Content-Description: File Transfer');
    335     header('Content-Disposition: attachment; filename="' . esc_attr(basename($file_path)) . '"');
    336     header('Content-Transfer-Encoding: binary');
    337     header('Content-Length: ' . $file_size);
    338     header('Connection: close');
    339 
    340     // Initialize WP_Filesystem
    341     require_once(ABSPATH . 'wp-admin/includes/file.php');
    342     WP_Filesystem();
    343     global $wp_filesystem;
    344 
    345     // Check if file exists and is readable
    346     if (!$wp_filesystem->exists($file_path)) {
    347         // Log error
    348         $seinc_backup_logs->add_log(
    349             'manual_download_error',
    350             $file,
    351             $backup_path,
    352             'error',
    353             'Backup file not found'
    354         );
    355         wp_die(esc_html__('Backup file not found', 'seinc-backup'));
    356     }
    357 
    358     // Get file contents using WP_Filesystem
     360    // Disable time limit for large files
     361    set_time_limit(0);
     362
     363    // Get and output file contents
    359364    $file_contents = $wp_filesystem->get_contents($file_path);
    360     if (false === $file_contents) {
    361         // Log error
     365    if ($file_contents === false) {
     366        // Log download error
    362367        $seinc_backup_logs->add_log(
    363368            'manual_download_error',
     
    382387        'Backup downloaded successfully'
    383388    );
    384     exit();
     389    exit;
    385390}
    386391add_action('admin_post_seinc_backup_download', 'seinc_backup_download');
Note: See TracChangeset for help on using the changeset viewer.