From 53fff911de3564c8688550452f138991730a704f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 22 Nov 2012 16:57:23 +0200 Subject: Added support for stream-like downloads of existing files to force_download() Based on code/ideas from PR #365, #1254 --- user_guide_src/source/helpers/download_helper.rst | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'user_guide_src/source/helpers/download_helper.rst') diff --git a/user_guide_src/source/helpers/download_helper.rst b/user_guide_src/source/helpers/download_helper.rst index 1e9ec21ea..860c568b9 100644 --- a/user_guide_src/source/helpers/download_helper.rst +++ b/user_guide_src/source/helpers/download_helper.rst @@ -21,7 +21,7 @@ force_download() .. php:function:: force_download($filename = '', $data = '', $set_mime = FALSE) :param string $filename: Filename - :param string $data: File contents + :param mixed $data: File contents :param bool $set_mime: Whether to try to send the actual MIME type :returns: void @@ -30,6 +30,9 @@ desktop. Useful with file downloads. The first parameter is the **name you want the downloaded file to be named**, the second parameter is the file data. +If you set the second parameter to NULL and ``$filename`` is an existing, readable +file path, then its content will be read instead. + If you set the third parameter to boolean TRUE, then the actual file MIME type (based on the filename extension) will be sent, so that if your browser has a handler for that type - it can use it. @@ -41,8 +44,7 @@ Example:: force_download($name, $data); If you want to download an existing file from your server you'll need to -read the file into a string:: +do the following:: - $data = file_get_contents('/path/to/photo.jpg'); // Read the file's contents - $name = 'myphoto.jpg'; - force_download($name, $data); \ No newline at end of file + // Contents of photo.jpg will be automatically read + force_download('/path/to/photo.jpg', NULL); \ No newline at end of file -- cgit v1.2.3-24-g4f1b