【问题标题】:Multiple Image file how to zip in codeigniter多个图像文件如何在codeigniter中压缩
【发布时间】:2019-04-23 18:55:45
【问题描述】:

我在文件夹中有多个图像,我在 href 按钮上得到它。那么如何在 codeigniter 中压缩该文件。

这是我的查看代码:

<a href="<?php echo base_url()."index.php/itr1/download/".$key['pan_card']."/".$key['previous_itr'] ?>" name="images">Downalod All Attachments</a>

这是我的控制器:

public function download()
{
    // File path
    $id =  $this->uri->segment(3); 
    $id1 =  $this->uri->segment(4); 

    $filepath1 = FCPATH.'upload/'.$id;
    $filepath2 = FCPATH.'upload/'.$id1;

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

【问题讨论】:

标签: php codeigniter


【解决方案1】:

使用 CI,它非常简单的 CI 有 zip 库,您可以使用它来压缩数据、文件或文件夹并下载它们,这里是创建 zip 和下载的方法

$id =  $this->uri->segment(3); 
$id1 =  $this->uri->segment(4); 

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

$filepath[] = FCPATH.'upload/'.$id;
$filepath[] = FCPATH.'upload/'.$id1;

foreach($filepaht as $file) {
  $this->zip->read_file($file);
}

// Download the file to your desktop. Name it "my_backup.zip"
$this->zip->download('my_backup.zip');

在此处阅读有关 zip 库的更多信息

https://www.codeigniter.com/user_guide/libraries/zip.html

【讨论】:

  • 调用未定义的方法 CI_Loader::read_file 以及这个错误
  • 那么如何加载 zip 库
  • 它的核心库在 CI 中可用,您可以在 system/libraries 文件夹中找到
  • @umefarooq 你可以通过写$this-&gt;load-&gt;library('zip');来添加zip库
  • @JaiminVyas 是的,您可以通过编写添加库。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-28
  • 2020-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-17
相关资源
最近更新 更多