Codeigniter – Записывать несколько направляющих в один файл с новой структурой каталогов

Я хочу объединить содержимое двух каталогов на моем сервере в один новый zip-файл.

Пример. Объедините содержимое / games / wheel / * и / games / SDK / com / * в корень нового zip-файла.

Существующая структура каталогов:

- games - SDK - com - folder1 - file1 - file1 - wheel - game_file1 - game_file2 

Новая структура каталогов (после распаковки нового файла):

 - folder1 - file1 - file2 - game_file1 - game_file2 

Используя текущую Zip-библиотеку codeigniter, как мне объединить существующую файловую структуру в новую и закрепить ее? Кто-нибудь продлил это, чтобы сделать это?

Solutions Collecting From Web of "Codeigniter – Записывать несколько направляющих в один файл с новой структурой каталогов"

MY_Zip.php – Расширить библиотеку почтовых индексов Codeigniter

 <?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) { 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 ($file != '.' and $file != '..' and is_dir($directory.$file)) { $this->add_dir($put_into.$file.'/'); $this->get_files_from_folder($directory.$file.'/', $put_into.$file.'/'); } }//end while }//end if closedir($handle); } } 

Применение:

 $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'); 

Результат:

 mybackup.zip/ - folder1 - file1 - file2 - game_file1 - game_file2