blob: 860c568b9fe0629c2bbdc7abd8bf58e092f0525c [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
7.. contents:: Page Contents
8
9Loading this Helper
10===================
11
Andrey Andreev48a86752012-11-08 15:16:34 +020012This helper is loaded using the following code::
Derek Jones8ede1a22011-10-05 13:34:52 -050013
14 $this->load->helper('download');
15
16The following functions are available:
17
Andrey Andreev48a86752012-11-08 15:16:34 +020018force_download()
19================
20
21.. php:function:: force_download($filename = '', $data = '', $set_mime = FALSE)
22
23 :param string $filename: Filename
Andrey Andreev53fff912012-11-22 16:57:23 +020024 :param mixed $data: File contents
Andrey Andreev48a86752012-11-08 15:16:34 +020025 :param bool $set_mime: Whether to try to send the actual MIME type
26 :returns: void
Derek Jones8ede1a22011-10-05 13:34:52 -050027
28Generates server headers which force data to be downloaded to your
29desktop. Useful with file downloads. The first parameter is the **name
30you want the downloaded file to be named**, the second parameter is the
Andrey Andreev48a86752012-11-08 15:16:34 +020031file data.
Derek Jones8ede1a22011-10-05 13:34:52 -050032
Andrey Andreev53fff912012-11-22 16:57:23 +020033If you set the second parameter to NULL and ``$filename`` is an existing, readable
34file path, then its content will be read instead.
35
Andrey Andreev48a86752012-11-08 15:16:34 +020036If you set the third parameter to boolean TRUE, then the actual file MIME type
37(based on the filename extension) will be sent, so that if your browser has a
38handler for that type - it can use it.
39
40Example::
Derek Jones8ede1a22011-10-05 13:34:52 -050041
42 $data = 'Here is some text!';
43 $name = 'mytext.txt';
44 force_download($name, $data);
45
46If you want to download an existing file from your server you'll need to
Andrey Andreev53fff912012-11-22 16:57:23 +020047do the following::
Derek Jones8ede1a22011-10-05 13:34:52 -050048
Andrey Andreev53fff912012-11-22 16:57:23 +020049 // Contents of photo.jpg will be automatically read
50 force_download('/path/to/photo.jpg', NULL);