doudouwen2763
2013-09-24 15:17 阅读 38
已采纳

在Codeigniter中创建加密的Zip

In my Codeigniter Controller I have the following code that zip the backup file from database. The problem is that when I extract the zip file, instead of single file inside, there are other folder from the path inside of it.

    $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'       => "
"                         // 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 .' ');

I'm not sure why the zip creates path folder inside the zip too. I mean instead of just archiving the backup.txt , it backup from the Application folder till to backup.txt file. After extracting the zip file I get below picture :

enter image description here

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    duanji4449 duanji4449 2013-09-24 15:41

    zip includes the paths to the files in the zip folder it creates by default. Add the -j flag to junk the paths and only include the file.

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

    Check out the man page for zip for more info.

    $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.
    
    点赞 评论 复制链接分享

相关推荐