Php 使用OHO Codeigniter备份MySQL数据库
我在确定zip备份文件的下载目标时遇到问题,zip文件的名称总是随机生成的,就像我得到的这个0ca26f32-b90c-4198-b078-ed2778a23c0b.zip但是压缩文件夹中的sql文件使用的是给定的名称backup_2019-01-24-22-33-03.sql PHP备份功能 下面的函数是下载一个压缩文件夹,其中包含windows中默认下载文件夹中的数据库sql文件Php 使用OHO Codeigniter备份MySQL数据库,php,mysql,codeigniter-3,database-backups,Php,Mysql,Codeigniter 3,Database Backups,我在确定zip备份文件的下载目标时遇到问题,zip文件的名称总是随机生成的,就像我得到的这个0ca26f32-b90c-4198-b078-ed2778a23c0b.zip但是压缩文件夹中的sql文件使用的是给定的名称backup_2019-01-24-22-33-03.sql PHP备份功能 下面的函数是下载一个压缩文件夹,其中包含windows中默认下载文件夹中的数据库sql文件 public function backup_get(){ $prefs = array(
public function backup_get(){
$prefs = array(
'tables' => array('convt', 'invoice', 'item', 'order_inv', 'person', 'return_details'), // Array of tables to backup.
'ignore' => array(), // List of tables to omit from the backup
'format' => 'zip', // gzip, zip, txt
'filename' => 'backup_' . date("Y-m-d-H-i-s") . '.sql', // File name - NEEDED ONLY WITH ZIP FILES
'add_drop' => true, // Whether to add DROP TABLE statements to backup file
'add_insert' => true, // Whether to add INSERT data to backup file
'newline' => "\n", // Newline character used in backup file
);
$backup = $this->dbutil->backup($prefs);
$db_name = 'backup-on-' . date("Y-m-d-H-i-s") . '.zip';
$save = './backup/' . $db_name;
$this->load->helper('file');
write_file($save, $backup);
http_response_code(200);
header('Content-Length: ' . filesize($save));
header("Content-Type: application/zip");
header('Content-Disposition: attachment; filename="backup.zip"');
readfile($save);
exit;
}
问题
我想将默认的目标表单下载
文件夹更改为我手动/自动生成的文件夹,并能够为zip文件命名
非常感谢您的帮助请尝试修改
backup\u get()
函数,如下所示:
public function backup_get(){
$prefs = array(
'tables' => array('convt', 'invoice', 'item', 'order_inv', 'person', 'return_details'), // Array of tables to backup.
'ignore' => array(), // List of tables to omit from the backup
'format' => 'zip', // gzip, zip, txt
'filename' => 'backup_' . date("Y-m-d-H-i-s") . '.sql', // File name - NEEDED ONLY WITH ZIP FILES
'add_drop' => true, // Whether to add DROP TABLE statements to backup file
'add_insert' => true, // Whether to add INSERT data to backup file
'newline' => "\n", // Newline character used in backup file
);
$backup = $this->dbutil->backup($prefs);
$db_name = 'backup-on-' . date("Y-m-d-H-i-s") . '.zip';
$backup_path = './backup/'; // this is the destination directory name
if (!file_exists($backup_path)) {
mkdir($backup_path, 0755, true);
}
$save = $backup_path . $db_name;
$this->load->helper('file');
write_file($save, $backup);
}
$backup\u路径是要设置的自定义目录