/** * Force the download of a file by the user's browser by preventing any * caching. Contains a workaround for Internet Explorer. * * @link http://support.microsoft.com/kb/316431 * @link http://support.microsoft.com/kb/812935 * * @uses download::dialog() * @uses download::send() * * @param string a file path or file name * @param mixed data to be sent if the filename does not exist * @param string suggested filename to display in the download * @return void */ public static function force($filename = NULL, $data = NULL, $nicename = NULL) { download::dialog(empty($nicename) ? $filename : $nicename); // Prevent caching header('Expires: Thu, 01 Jan 1970 00:00:00 GMT'); if (request::user_agent('browser') === 'Internet Explorer' and request::user_agent('version') <= '6.0') { // HTTP 1.0 header('Pragma:'); // HTTP 1.1 with IE extensions header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); } else { // HTTP 1.0 header('Pragma: no-cache'); // HTTP 1.1 header('Cache-Control: no-cache, max-age=0'); } if (is_file($filename)) { download::send($filename); } else { download::send($filename, $data); } }
public function media($type = NULL, $file = NULL) { // Get the file path from the request $file = implode('/', URI::instance()->segment_array(2)); // Find the file extension $ext = pathinfo($file, PATHINFO_EXTENSION); // Remove the extension from the filename $file = substr($file, 0, -(strlen($ext) + 1)); // Find the file if (!($file = Kohana::find_file('media', $file, FALSE, $ext))) { Event::run('system.404'); } // Tell browsers to cache the file for an hour. Chrome especially seems to not want to cache things expires::check(3600); // Send the file content as the response, and send some basic headers download::send($file); }