Codeigniter 3 create zip file and download example

Codeigniter 3 create zip file and download example

In this post we will give you information about Codeigniter 3 create zip file and download example. Hear we will give you detail about Codeigniter 3 create zip file and download exampleAnd how to use it also give you demo for it if it is necessary.

Sometime, we may require to create and download zip file in codeigniter 3 project. In this tutorial, i will show you how to create zip file in codeigniter using zip library.

Whenever, we have lot’s of files and need to give download to user when click on submit button, at that we never give one by one file to download because it is small size of files might be and it take time to download one by one. But if you create zip file and put all the files on zip then it can be very fast download and user don’t need to wait so much time. So, in this example i will let you know how you can create zip file with download in codeigniter application.

Here, we will just create one route for download zip file with one “ZipController”. i write creating zip file code and download code on index(). So just follow this two things.

Create Route:

In this step we need to add one route for download zip file after creating. so open routes.php file and add code like as bellow:

application/config/routes.php

$route['create-zip'] = "ZipController";

Create Controller:

Here, we need to create ZipController with index() method. I write creating zip file code and download code on index(). Let’s just create it.

application/controllers/ZipController.php

Also see:PHP Codeigniter 3 – Create Dynamic Tree View using Bootstrap Treeview JS

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class ZipController extends CI_Controller {

/**

* Get All Data from this method.

*

* @return Response

*/

public function __construct() {

parent::__construct();

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

}

/**

* Get All Data from this method.

*

* @return Response

*/

public function index()

{

$fileName = 'onlinecode.txt';

$fileData = 'This file created by Itsolutionstuff.com';

$this->zip->add_data($fileName, $fileData);

$fileName2 = 'onlinecode_file2.txt';

$fileData2 = 'This file created by Itsolutionstuff.com - 2';

$this->zip->add_data($fileName2, $fileData2);

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

}

}

Now you can run and see how it works.

I hope it can help you…

Hope this code and post will helped you for implement Codeigniter 3 create zip file and download example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

8  +  2  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US