在我的 Codeigniter 控制器中,我有以下代码从数据库中压缩备份文件。问题是,当我提取 zip 文件时,其中的路径不是单个文件,而是其中的路径中的其他文件夹。
$this->load->dbutil();
$this->load->helper('date');
$this->load->helper('file');
set_time_limit(0);
$prefs = array(
'format' => 'txt', // gzip, zip, txt
'filename' => 'backup.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);
$file = FCPATH.'GB_dump_backup/backup.txt';
$zip = FCPATH.'GB_dump_backup/'.now().'backup';
write_file($file, $backup);
system('zip -P pass '.$zip.' '.$file .' ');
我不确定为什么 zip 也会在 zip 中创建路径文件夹。我的意思是,它不仅仅是归档 backup.txt ,而是从 Application 文件夹备份到 backup.txt 文件。提取 zip 文件后,我得到下图: