0

This my controller function in which i used database util library to crate backup for database. When i download a backup the zip file cannot be opened with zip extractor. What should I do?

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 Answer 1

1

This is a function I use, to perform a database backup.

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

The only thing I can notice that's different is the file name in the backup() function. According to the user guide, you only need to add the file name to the backup() array, if it's a .zip file.

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

Sign up to request clarification or add additional context in comments.

2 Comments

Quote: "you only need to add the file name to the backup() array, if it's a .zip file" ~ Isn't that what the OP is already doing?
No. He is using "$name.sql"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.