From a8027ffc90ef80819fba01209fa57f810e2104af Mon Sep 17 00:00:00 2001 From: Joseba Juániz Date: Wed, 6 Aug 2014 20:03:25 +0200 Subject: Change name didn't work if reset initialization it's true If user initializes the upload library with the reset flag as true, the uploaded file doesn't change it's name, it's neccesary to initialize or change the $_file_name_override every time. --- system/libraries/Upload.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'system/libraries/Upload.php') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 75fc0624f..7946111cc 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -327,23 +327,26 @@ class CI_Upload { $this->$key = $defaults[$key]; } } - - return $this; + } - - foreach ($config as $key => &$value) + else { - if ($key[0] !== '_' && $reflection->hasProperty($key)) + + foreach ($config as $key => &$value) { - if ($reflection->hasMethod('set_'.$key)) - { - $this->{'set_'.$key}($value); - } - else + if ($key[0] !== '_' && $reflection->hasProperty($key)) { - $this->$key = $value; + if ($reflection->hasMethod('set_'.$key)) + { + $this->{'set_'.$key}($value); + } + else + { + $this->$key = $value; + } } } + } // if a file_name was provided in the config, use it instead of the user input -- cgit v1.2.3-24-g4f1b From f38c9c29e32e86d453c820bdc13abdd9c2a1a765 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 27 Aug 2014 14:56:31 +0300 Subject: Close #3205 --- system/libraries/Upload.php | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) (limited to 'system/libraries/Upload.php') diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 7946111cc..49c69a32c 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -1158,28 +1158,14 @@ class CI_Upload { */ protected function _prep_filename($filename) { - if ($this->mod_mime_fix === FALSE OR $this->allowed_types === '*' OR strpos($filename, '.') === FALSE) + if ($this->mod_mime_fix === FALSE OR $this->allowed_types === '*' OR ($ext_pos = strrpos($filename, '.')) === FALSE) { return $filename; } - $parts = explode('.', $filename); - $ext = array_pop($parts); - $filename = array_shift($parts); - - foreach ($parts as $part) - { - if ( ! in_array(strtolower($part), $this->allowed_types) OR ! isset($this->_mimes[strtolower($part)])) - { - $filename .= '.'.$part.'_'; - } - else - { - $filename .= '.'.$part; - } - } - - return $filename.'.'.$ext; + $ext = substr($filename, $ext_pos); + $filename = substr($filename, 0, $ext_pos); + return str_replace('.', '_', $filename).$ext; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b