CodeIgniter Download Helper
×

CodeIgniter Download Helper

1625

Download helper contains functions that help us for downloading data to our desktop.


Related Topics:

Codeigniter Interview Questions
CodeIgniter Text helper
CodeIgniter Directory helper

Loading this Helper:

Use the given line in your controller or model file to load the download helper.

$this->load->helper("download");

The following functions are available in this helper:

1 force_download(): This function is used to generates server headers which force data to be downloaded to your desktop.

Syntax:

force_download([name = ''[, $data = ''[, $set_mime = FALSE]]]);

Parameter Description:

  • name (string) – Filename
  • $data (mixed) – File contents
  • $set_mime (bool) – Whether to try to send the actual MIME-type

The return type of this function is void.

  • Example:

Step 1 Open the application/controllers directory and create a new controller file Force_download.php

<?php
class Force_download extends CI_Controller {

public function index() {
$this->load->helper('download'); //load download helper
$data = 'Here is some text!';
$name = 'mytext.txt';
force_download($name, $data);
}
}
?>

Step 2 Open the given URL into the browser to see the result.

http://localhost/ci/index.php/Force_download

Note:

You can also download an existing file from your server by using this function.


  • Example 2:

Step 1 Open the application/controllers directory and create a new controller file Force_download1.php

<?php
class Force_download1 extends CI_Controller {

public function index() {
$this->load->helper('download'); //load download helper
force_download('uploads/icon-1.png', NULL);
}
}
?>

Step 2 Open the given URL into the browser to see the result.

http://localhost/ci/index.php/Force_download1



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments