Syed mohamed aladeen
Syed mohamed aladeen

Reputation: 6755

how to zip multiple folders in codeigniter

I am trying to zip multiple folders in codeigniter.

here is my code

public function zip_files()
{
  $this->load->library('zip');
  $this->zip->compression_level = 0;

  $path1 = '/my folder path';
  $this->zip->read_dir($path1);

  $path2 = '/my another folder path';
  $this->zip->read_dir($path2);

  $this->zip->download('my_upoads.zip');
}

but the above code zips only the $path2 folder.

how to zip multiple folders? this is my question

Thankyou, syed

Upvotes: 0

Views: 4142

Answers (2)

muhammed hunkar
muhammed hunkar

Reputation: 36

you can use clean data

$this->zip->clear_data();

example :

$name = 'my_bio.txt';
$data = 'I was born in an elevator...';

$this->zip->add_data($name, $data);
$zip_file = $this->zip->get_zip();

$this->zip->clear_data();

$name = 'photo.jpg';
$this->zip->read_file("/path/to/photo.jpg"); // Read the file's contents

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

Upvotes: 2

mokNathal
mokNathal

Reputation: 553

You can use $this->zip->read_dir()

refer: https://ellislab.com/codeigniter/user-guide/libraries/zip.html

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

$path = '/path/to/your/directory/';

$this->zip->read_dir($path);

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

you have to supply base folder then it will zip all folders, files within it in single zip file.

Upvotes: 2

Related Questions