0
votes

I have multiple image in folder, and I get it on href button. So how to zip that file in codeigniter.

Here is my View Code:

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

Here is my Controller:

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);
}
1
You can probably copy the required images in a temp folder and then use the solution mentioned here. stackoverflow.com/questions/4914750/…Danish Hakim Khan
check my answerumefarooq

1 Answers

0
votes

with CI its really simple CI has zip library you can use to zip data, files or folder and download them here is how you can create zip and download

$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');

Read more about zip library here

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