2014-07-02 31 views
0

這是我的控制器功能,我使用數據庫實用程序庫爲數據庫備份備份。當我下載備份時,無法使用zip提取器打開zip文件。我該怎麼辦?Codeigniter數據庫備份不能返回可讀文件

function backup_database() { 

     $file_name = 'accounts'; 
     $date = date('@Y.m.d-H.ia'); 

     $name = $file_name . $date; 

     // Load the DB utility class 
     $this->load->dbutil(); 

     // Backup entire database and assign it to a variable 
     $backup = & $this->dbutil->backup(array('filename' => "$name.sql")); 

     // Load the file helper and write the file to server 
     $this->load->helper('file'); 
     write_file("$name.zip", $backup); 

     // Load the download helper and send the file to desktop 
     $this->load->helper('download'); 
     force_download("$name.zip", $backup); 
    } 

回答

1

這是我用來執行數據庫備份的功能。

function _backup_db() 
{ 
    $this->load->dbutil(); 
    $this->load->helper(array('file', 'download')); 

    $backup =& $this->dbutil->backup(); 

    $filename = 'backup-' . time() . ' .zip'; 

    write_file('/backups/' . $filename, $backup); 
    force_download($filename, $backup); 
} 

我可以注意到,唯一不同的是backup()函數中的文件名。根據用戶指南,只需將文件名添加到backup()數組(如果它是.zip文件)。

http://ellislab.com/codeigniter/user-guide/database/utilities.html#backup

+0

報價:_「你只需要到文件名添加到備份()數組,如果它是一個.zip文件」 _〜是不是那個什麼OP已經在做? – Sparky

+0

不。他正在使用「$ name.sql」 – Craig