2012-06-24 5 views
0

Codeigniter застегивает весь путь источника.Codeigniter: zip только папка назначения

Как закрепить только папку назначения?

+0

Приведите пример – Jones

+0

, например. если я пытаюсь zip/public/products/images, тогда он должен только застегивать папку с изображениями не весь путь, в настоящее время он застегивает весь путь, т. е. из/public/products/images – CBM

ответ

1

такая возможность

$folder_in_zip = "/"; //root directory of the new zip file 

$path = 'games/SDK/com/'; 
$this->zip->get_files_from_folder($path, $folder_in_zip); 

$path = 'games/wheel/'; 
$this->zip->get_files_from_folder($path, $folder_in_zip); 

$this->zip->download('my_backup.zip'); 

Без рекурсии

<?php if (!defined('BASEPATH')) exit('No direct script access allowed.'); 

class MY_Zip extends CI_Zip 
{ 
    /** 
    * Read a directory and add it to the zip using the new filepath set. 
    * 
    * This function recursively reads a folder and everything it contains (including 
    * sub-folders) and creates a zip based on it. You must specify the new directory structure. 
    * The original structure is thrown out. 
    * 
    * @access public 
    * @param string path to source 
    * @param string new directory structure 
    */ 
    function get_files_from_folder($directory, $put_into, $recursion = false) 
    { 
     if ($handle = opendir($directory)) 
     { 
      while (false !== ($file = readdir($handle))) 
      { 
       if (is_file($directory.$file)) 
       { 
        $fileContents = file_get_contents($directory.$file); 

        $this->add_data($put_into.$file, $fileContents); 

       } 

       elseif ($recursion and $file != '.' and $file != '..' and is_dir($directory.$file)) { 

        $this->add_dir($put_into.$file.'/'); 

        $this->get_files_from_folder($directory.$file.'/', $put_into.$file.'/', $recursion); 
       } 

      }//end while 

     }//end if 

     closedir($handle); 
    } 
} 

Этот экстракт from this question

2

В $ this-> zip-> read_dir() передать FALSE во втором параметре.

$ this-> zip-> read_dir ($ path, FALSE);

Смежные вопросы