0

Codeigniter はソース パス全体を圧縮します。

宛先フォルダーのみを圧縮する方法は?

4

3 に答える 3

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);
    }
}

この質問からのこの抜粋

于 2012-06-24T19:57:23.987 に答える