2013-09-24 35 views
0

在我的Codeigniter控制器中,我有以下代码从数据库中压缩备份文件。问题是,当我提取zip文件而不是单个文件时,里面还有其他文件夹。在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文件后,我得到如下图:

enter image description here

回答

1

zip包括路径在它默认创建的zip文件夹中的文件。将-j标志添加到j中,并且只包含该文件。

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

退房为zip man页面获取更多信息。

$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.