0

在我的 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 文件后,我得到下图:

在此处输入图像描述

4

1 回答 1

1

zip包括默认情况下创建的 zip 文件夹中文件的路径。添加-j标志以j取消路径并仅包含文件。

system('zip -j -P pass '.$zip.' '.$file .' ');

查看手册页以zip获取更多信息。

$man zip
...
   -p
   --paths
          Include relative file paths as part of the names of files stored in the ar-
          chive.  This is the default.  The -j option junks the paths and just stores
          the names of the files.
于 2013-09-24T15:41:22.653 回答