This is documentation for Kohana v2.3.x.
Status | Draft |
---|---|
Todo | Proof read |
The download helper assists in forcing downloading of files by presenting users with the “save as” dialog.
'force' forces a download of a file to the user's browser. This function is binary-safe and will work with any MIME type that Kohana is aware of.
Example:
// File path is relative to the front controller download::force("file.txt"); // For a file located in application/downloads // Use relative path download::force('./application/downloads/file.txt'); // OR use the defined application path download::force(APPPATH.'downloads/file.txt'); // Example usage in a controller public function download($file) { // Keep extra page output from being added to your file $this->auto_render = false; // Don't forget to 'return' the result otherwise nothing happens return download::force($file); } // Suggesting a file name - browser will prompt to save the file as 'latest-results.xml' download::force($file, NULL, 'latest-results.xml');