【问题标题】:Creating Encrypted Zip in Codeigniter在 Codeigniter 中创建加密的 Zip
【发布时间】:2013-09-24 15:17:34
【问题描述】:

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

【问题讨论】:

    标签: php apache codeigniter zip system


    【解决方案1】:

    zip 包含默认情况下创建的 zip 文件夹中文件的路径。将-j 标志添加到junk 路径并仅包含该文件。

    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.
    

    【讨论】:

      猜你喜欢
      • 2015-01-11
      • 1970-01-01
      • 1970-01-01
      • 2022-11-04
      • 2010-11-09
      • 1970-01-01
      • 2016-08-29
      • 1970-01-01
      • 2010-12-26
      相关资源
      最近更新 更多