开发者

codeigniter Zip Encoding Class add multiple files

开发者 https://www.devze.com 2023-02-09 07:41 出处:网络
heres how I am doing now : $path = \"./uploads/1.txt\"; $path1 =\"./uploads/4.txt\"; $this->zip->read_file($path);

heres how I am doing now :

$path = "./uploads/1.txt";
$path1 =  "./uploads/4.txt";
$this->zip->read_file($path);
$this->zip->read_file($path1);
$this->zip->download('files_backup.zip');

Now I want to add the files from 开发者_开发知识库a database query which returns the path of the files .

$data['query'] = $this->db->get_where('files', array('uid'=>$uid));

now please tell me which loop that I must use in order to call $this->zip->read_file($path);

from the results of the query mentioned above..

thanks

Edit:

foreach ($query->result() as $row)
{
    echo $row->filename;
}

result

335476sfsr.txt 
egyafhwe7g.txt
4566weyt36.txt

so, it just shows the files of that user ..


ok, so then just edit the given loop like so

foreach ($query->result() as $row)
{
    $this->zip->read_file($row->filename);
}

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


Make a database with a table ITEMS and add IMG column then use this code.

View:

 <form method='post' action='<?= base_url() ?>index.php/zip/createzip/'>
            <input type="submit" name="but_createzip1" value='Add file from path and download zip'>
 </form>

Controller:

public function createzip(){

      // Load zip library
      $this->load->library('zip');

      $query = $this->db->get('items');

      foreach ($query->result() as $row)
        {
          $fileName = FCPATH."./uploads/".$row->img;
          $this->zip->read_file($fileName);
        }

       $filename = "backup.zip";
       $this->zip->download($filename);
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消