我在文件夹中有多个图像,我在href按钮上得到了它。那么如何在代码点火器中压缩该文件。
这是我的视图代码:
<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);
}
使用CI,它非常简单的CI具有zip库,您可以使用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