blob: 1a4065073106b6c2ba4cab103df7592254881672 [file] [log] [blame]
Derek Jones8ede1a22011-10-05 13:34:52 -05001###############
2Download Helper
3###############
4
5The Download Helper lets you download data to your desktop.
6
Derek Jones7e69fea2013-07-21 10:57:25 -07007.. contents::
8 :local:
9
10.. raw:: html
11
12 <div class="custom-index container"></div>
Derek Jones8ede1a22011-10-05 13:34:52 -050013
14Loading this Helper
15===================
16
Andrey Andreev48a86752012-11-08 15:16:34 +020017This helper is loaded using the following code::
Derek Jones8ede1a22011-10-05 13:34:52 -050018
19 $this->load->helper('download');
20
Derek Jones7e69fea2013-07-21 10:57:25 -070021Available Functions
22===================
23
Derek Jones8ede1a22011-10-05 13:34:52 -050024The following functions are available:
25
Andrey Andreev48a86752012-11-08 15:16:34 +020026
Andrey Andreevcd3d9db2015-02-02 13:41:01 +020027.. php:function:: force_download([$filename = ''[, $data = ''[, $set_mime = FALSE]]])
Andrey Andreev48a86752012-11-08 15:16:34 +020028
29 :param string $filename: Filename
Andrey Andreev53fff912012-11-22 16:57:23 +020030 :param mixed $data: File contents
Andrey Andreev48a86752012-11-08 15:16:34 +020031 :param bool $set_mime: Whether to try to send the actual MIME type
Andrey Andreev3de130c2014-02-07 23:31:49 +020032 :rtype: void
Derek Jones8ede1a22011-10-05 13:34:52 -050033
Derek Jones7e69fea2013-07-21 10:57:25 -070034 Generates server headers which force data to be downloaded to your
35 desktop. Useful with file downloads. The first parameter is the **name
36 you want the downloaded file to be named**, the second parameter is the
37 file data.
Derek Jones8ede1a22011-10-05 13:34:52 -050038
Derek Jones7e69fea2013-07-21 10:57:25 -070039 If you set the second parameter to NULL and ``$filename`` is an existing, readable
40 file path, then its content will be read instead.
Andrey Andreev53fff912012-11-22 16:57:23 +020041
Derek Jones7e69fea2013-07-21 10:57:25 -070042 If you set the third parameter to boolean TRUE, then the actual file MIME type
43 (based on the filename extension) will be sent, so that if your browser has a
44 handler for that type - it can use it.
Andrey Andreev48a86752012-11-08 15:16:34 +020045
Derek Jones7e69fea2013-07-21 10:57:25 -070046 Example::
Derek Jones8ede1a22011-10-05 13:34:52 -050047
Derek Jones7e69fea2013-07-21 10:57:25 -070048 $data = 'Here is some text!';
49 $name = 'mytext.txt';
50 force_download($name, $data);
Derek Jones8ede1a22011-10-05 13:34:52 -050051
Derek Jones7e69fea2013-07-21 10:57:25 -070052 If you want to download an existing file from your server you'll need to
53 do the following::
Derek Jones8ede1a22011-10-05 13:34:52 -050054
Derek Jones7e69fea2013-07-21 10:57:25 -070055 // Contents of photo.jpg will be automatically read
56 force_download('/path/to/photo.jpg', NULL);