Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | ############### |
| 2 | Download Helper |
| 3 | ############### |
| 4 | |
| 5 | The Download Helper lets you download data to your desktop. |
| 6 | |
| 7 | .. contents:: Page Contents |
| 8 | |
| 9 | Loading this Helper |
| 10 | =================== |
| 11 | |
| 12 | This helper is loaded using the following code |
| 13 | |
| 14 | :: |
| 15 | |
| 16 | $this->load->helper('download'); |
| 17 | |
| 18 | The following functions are available: |
| 19 | |
| 20 | force_download('filename', 'data') |
| 21 | ================================== |
| 22 | |
| 23 | Generates server headers which force data to be downloaded to your |
| 24 | desktop. Useful with file downloads. The first parameter is the **name |
| 25 | you want the downloaded file to be named**, the second parameter is the |
| 26 | file data. Example |
| 27 | |
| 28 | :: |
| 29 | |
| 30 | $data = 'Here is some text!'; |
| 31 | $name = 'mytext.txt'; |
| 32 | force_download($name, $data); |
| 33 | |
| 34 | If you want to download an existing file from your server you'll need to |
| 35 | read the file into a string |
| 36 | |
| 37 | :: |
| 38 | |
| 39 | $data = file_get_contents("/path/to/photo.jpg"); // Read the file's contents |
| 40 | $name = 'myphoto.jpg'; |
| 41 | force_download($name, $data); |
| 42 | |