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

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题