From 5d1cacfeadacb03dc8cb4dcb334a3e18db4fc5d7 Mon Sep 17 00:00:00 2001 From: Adrian Date: Mon, 24 Jun 2013 14:39:52 +0200 Subject: Force the file extension to lower case --- system/libraries/Upload.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 7c48b4294..9c2b45659 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -965,7 +965,7 @@ class CI_Upload { public function get_extension($filename) { $x = explode('.', $filename); - return (count($x) !== 1) ? '.'.end($x) : ''; + return (count($x) !== 1) ? '.'.strtolower(end($x)) : ''; } // -------------------------------------------------------------------- @@ -1284,4 +1284,4 @@ class CI_Upload { } /* End of file Upload.php */ -/* Location: ./system/libraries/Upload.php */ \ No newline at end of file +/* Location: ./system/libraries/Upload.php */ -- cgit v1.2.3-24-g4f1b From f496d13ee26c13b3406d30013206af679bf68922 Mon Sep 17 00:00:00 2001 From: Adrian Date: Mon, 24 Jun 2013 15:56:45 +0200 Subject: Add a config var to let the choice of having the lower case on the extensions when uploading. The default value is set to FALSE. --- system/libraries/Upload.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 9c2b45659..14863d69a 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -135,6 +135,13 @@ class CI_Upload { */ public $file_ext = ''; + /** + * Force filename extension to lowercase + * + * @var string + */ + public $file_ext_case = FALSE; + /** * Upload path * @@ -294,6 +301,7 @@ class CI_Upload { 'file_type' => '', 'file_size' => NULL, 'file_ext' => '', + 'file_ext_case' => FALSE, 'upload_path' => '', 'overwrite' => FALSE, 'encrypt_name' => FALSE, @@ -965,7 +973,11 @@ class CI_Upload { public function get_extension($filename) { $x = explode('.', $filename); - return (count($x) !== 1) ? '.'.strtolower(end($x)) : ''; + + if($this->file_ext_case) + return (count($x) !== 1) ? '.'.strtolower(end($x)) : ''; + else + return (count($x) !== 1) ? '.'.end($x) : ''; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 74a228b0b842e4aeb8cc9326c5d10c1fe4f4ce06 Mon Sep 17 00:00:00 2001 From: Adrian Date: Tue, 25 Jun 2013 12:09:22 +0200 Subject: New var name to make it more comprehensive Changes to follow the styleguide, proposed by narfbg (thanks to him) --- system/libraries/Upload.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'system/libraries') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 14863d69a..5861df584 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -140,7 +140,7 @@ class CI_Upload { * * @var string */ - public $file_ext_case = FALSE; + public $file_ext_tolower = FALSE; /** * Upload path @@ -301,7 +301,7 @@ class CI_Upload { 'file_type' => '', 'file_size' => NULL, 'file_ext' => '', - 'file_ext_case' => FALSE, + 'file_ext_tolower' => FALSE, 'upload_path' => '', 'overwrite' => FALSE, 'encrypt_name' => FALSE, @@ -974,10 +974,13 @@ class CI_Upload { { $x = explode('.', $filename); - if($this->file_ext_case) - return (count($x) !== 1) ? '.'.strtolower(end($x)) : ''; - else - return (count($x) !== 1) ? '.'.end($x) : ''; + if (count($x) === 1) + { + return ''; + } + + $ext = ($this->file_ext_tolower) ? strtolower(end($x)) : end($x); + return '.'.$ext; } // -------------------------------------------------------------------- @@ -1296,4 +1299,4 @@ class CI_Upload { } /* End of file Upload.php */ -/* Location: ./system/libraries/Upload.php */ +/* Location: ./system/libraries/Upload.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b