0

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);
}
Nipun
  • 990
  • 1
  • 16
  • 25
jaydev vara
  • 17
  • 11

1 Answers1

0

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

umefarooq
  • 4,540
  • 1
  • 29
  • 38