Codeigniter:仅压缩目标文件夹

时间:2012-06-24 04:45:35

标签: codeigniter

Codeigniter会压缩整个源路径。

如何仅压缩目标文件夹?

3 个答案:

答案 0 :(得分:2)

在$ this-> zip-> read_dir()中,在第二个参数中传递FALSE。

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

答案 1 :(得分: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 :(得分:-1)

控制器

上传Zip文件

public function UploadFile() {
  $name_array = array();
  $count = count($_FILES['userfile']['size']);
  foreach($_FILES as $key=>$value)
  for($s=0; $s<=$count-1; $s++) {
          $_FILES['userfile']['name']=$value['name'][$s];
          $_FILES['userfile']['type']    = $value['type'][$s];
          $_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
          $_FILES['userfile']['error']       = $value['error'][$s];
          $_FILES['userfile']['size']    = $value['size'][$s];
          $config['upload_path'] = './Debra2recording/';
          $config['allowed_types'] = 'zip';
          $config['max_size']    = '104857600';
          $this->load->library('upload', $config);
          $this->upload->do_upload();
          $data = $this->upload->data();
          $name_array[] = $data['file_name'];
  }
        $names= implode(',', $name_array);

        $this->session->set_flashdata('message', 'Your Data imported successfully..');
       redirect('debra_forbes2/index');
        print_r($names);

  }

**下载ZIP文件**

     public function downloadall()
      {

      $this->load->library('zip');
      $path = './Debra2recording/';
      $this->zip->read_dir($path);
      $this->zip->download('Debra2recording.zip');

      }