【问题标题】:Codeigniter Database backup not returning readable fileCodeigniter 数据库备份不返回可读文件
【发布时间】:2014-07-02 08:58:03
【问题描述】:

这是我的控制器功能,我在其中使用数据库实用程序库为数据库创建备份。当我下载备份时,无法使用 zip 提取器打开 zip 文件。我该怎么办?

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);
    }

【问题讨论】:

    标签: database codeigniter backup codeigniter-2


    【解决方案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() 函数中的文件名。根据用户指南,如果是 .zip 文件,您只需将文件名添加到 backup() 数组中。

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

    【讨论】:

    • 引用:“如果是.zip文件,你只需要将文件名添加到backup()数组中”~OP不是已经这样了在做什么?
    • 没有。他正在使用“$name.sql”
    猜你喜欢
    • 2015-06-04
    • 1970-01-01
    • 2013-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多