doudouwen2763 2013-09-24 15:17
浏览 39
已采纳

在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 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.
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码