diff options
author | Timothy Warren <tim@timshomepage.net> | 2012-06-12 13:45:45 +0200 |
---|---|---|
committer | Timothy Warren <tim@timshomepage.net> | 2012-06-12 13:45:45 +0200 |
commit | b30a7c0d53c5dae5dab2311f777d67f639a5cee4 (patch) | |
tree | d518bc938a5d8458a55277d9adaa7d8fdcc9f1d3 /system/helpers/file_helper.php | |
parent | 3902e383b41c6c0ef77b65e95d451cb2ea3d85db (diff) | |
parent | 4e9538fe19b09c0dc588542cfb7f793348b83bf7 (diff) |
Merge upstream
Diffstat (limited to 'system/helpers/file_helper.php')
-rw-r--r-- | system/helpers/file_helper.php | 58 |
1 files changed, 11 insertions, 47 deletions
diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 0061c4285..be616f62d 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -44,38 +44,15 @@ if ( ! function_exists('read_file')) * * Opens the file specfied in the path and returns it as a string. * + * This function is DEPRECATED and should be removed in + * CodeIgniter 3.1+. Use file_get_contents() instead. + * * @param string path to file * @return string */ function read_file($file) { - if ( ! file_exists($file)) - { - return FALSE; - } - - if (function_exists('file_get_contents')) - { - return file_get_contents($file); - } - - if ( ! $fp = @fopen($file, FOPEN_READ)) - { - return FALSE; - } - - flock($fp, LOCK_SH); - - $data = ''; - if (filesize($file) > 0) - { - $data =& fread($fp, filesize($file)); - } - - flock($fp, LOCK_UN); - fclose($fp); - - return $data; + return @file_get_contents($file); } } @@ -349,36 +326,23 @@ if ( ! function_exists('get_mime_by_extension')) { $extension = strtolower(substr(strrchr($file, '.'), 1)); - global $mimes; + static $mimes; if ( ! is_array($mimes)) { - if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) - { - include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'); - } - elseif (is_file(APPPATH.'config/mimes.php')) - { - include(APPPATH.'config/mimes.php'); - } + $mimes =& get_mimes(); - if ( ! is_array($mimes)) + if (empty($mimes)) { return FALSE; } } - if (array_key_exists($extension, $mimes)) + if (isset($mimes[$extension])) { - if (is_array($mimes[$extension])) - { - // Multiple mime types, just give the first one - return current($mimes[$extension]); - } - else - { - return $mimes[$extension]; - } + return is_array($mimes[$extension]) + ? current($mimes[$extension]) // Multiple mime types, just give the first one + : $mimes[$extension]; } return FALSE; |