Changeset 2982 for trunk/system/helpers/download.php
- Timestamp:
- 07/07/2008 12:59:03 PM (5 months ago)
- Files:
-
- 1 modified
-
trunk/system/helpers/download.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/helpers/download.php
r2373 r2982 22 22 public static function force($filename = '', $data = '') 23 23 { 24 static $user_agent; 25 26 if ($filename == '') 24 if (empty($filename)) 27 25 return FALSE; 28 26 … … 32 30 $filepath = str_replace('\\', '/', realpath($filename)); 33 31 32 // Set filesize 33 $filesize = filesize($filepath); 34 35 // Get filename 36 // Note: Do not use pathinfo for this, it may not be utf8 compatible 37 $filename = end(explode('/', $filepath)); 38 34 39 // Get extension 35 40 $extension = pathinfo($filepath, PATHINFO_EXTENSION); 36 37 // Remove directory path from the filename38 $filename = end(explode('/', $filepath));39 40 // Set filesize41 $filesize = filesize($filepath);42 41 } 43 42 else 44 43 { 45 // Grab the file extension 44 // Get filesize 45 $filesize = strlen($data); 46 47 // Make sure the filename does not have directory info 48 $filename = end(explode('/', $filename)); 49 50 // Get extension 46 51 $extension = end(explode('.', $filename)); 47 48 // Try to determine if the filename includes a file extension.49 // We need it in order to set the MIME type50 if (empty($data) OR $extension === $filename)51 return FALSE;52 53 // Set filesize54 $filesize = strlen($data);55 52 } 56 53 57 // Set a default mime if we can't find it 58 if (($mime = Config::item('mimes.'.$extension)) === NULL) 54 // Get the mime type of the file 55 $mime = Config::item('mimes.'.$extension); 56 57 if (empty($mime)) 59 58 { 60 $mime = 'application/octet-stream'; 61 } 62 else 63 { 64 $mime = current((array) $mime); 59 // Set a default mime if none was found 60 $mime = array('application/octet-stream'); 65 61 } 66 62 67 63 // Generate the server headers 68 header('Content-Type: '.$mime );64 header('Content-Type: '.$mime[0]); 69 65 header('Content-Disposition: attachment; filename="'.$filename.'"'); 70 66 header('Content-Transfer-Encoding: binary'); 67 header('Content-Length: '.sprintf('%d', $filesize)); 68 69 // More caching prevention 71 70 header('Expires: 0'); 72 header('Content-Length: '.$filesize);73 71 74 // IE headers75 72 if (Kohana::user_agent('browser') === 'Internet Explorer') 76 73 { 74 // Send IE headers 77 75 header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 78 76 header('Pragma: public'); … … 80 78 else 81 79 { 80 // Send normal headers 82 81 header('Pragma: no-cache'); 83 82 } 83 84 // Flush the output buffer 85 Kohana::close_buffers(FALSE); 84 86 85 87 if (isset($filepath))
