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(-) 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(-) 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(-) 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 From eac8b2f1e70e3155ae6bacbc37228a0a647a18be Mon Sep 17 00:00:00 2001 From: Adrian Date: Fri, 28 Jun 2013 13:54:40 +0200 Subject: Update library documentation and changelog --- user_guide_src/source/changelog.rst | 1 + user_guide_src/source/libraries/file_uploading.rst | 1 + 2 files changed, 2 insertions(+) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 38c6d05bd..44ae52492 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -217,6 +217,7 @@ Release Date: Not Released - Added an **index** parameter to the ``data()`` method. - Added the **min_width** and **min_height** options for images. - Removed method ``clean_file_name()`` and its usage in favor of :doc:`Security Library `'s ``sanitize_filename()``. + - Added **file_ext_tolower** config setting. - :doc:`Cart library ` changes include: - ``insert()`` now auto-increments quantity for an item when inserted twice instead of resetting it, this is the default behaviour of large e-commerce sites. - *Product Name* strictness can be disabled by switching the ``$product_name_safe`` property to FALSE. diff --git a/user_guide_src/source/libraries/file_uploading.rst b/user_guide_src/source/libraries/file_uploading.rst index c7965ae11..a92d3af34 100644 --- a/user_guide_src/source/libraries/file_uploading.rst +++ b/user_guide_src/source/libraries/file_uploading.rst @@ -198,6 +198,7 @@ Preference Default Value Options Descripti **file_name** None Desired file name If set CodeIgniter will rename the uploaded file to this name. The extension provided in the file name must also be an allowed file type. If no extension is provided in the original file_name will be used. +**file_ext_tolower** FALSE TRUE/FALSE (boolean) If set to TRUE, the file extension will be forced to lower case **overwrite** FALSE TRUE/FALSE (boolean) If set to true, if a file with the same name as the one you are uploading exists, it will be overwritten. If set to false, a number will be appended to the filename if another with the same name exists. -- cgit v1.2.3-24-g4f1b