Index: branches/5.2.x/core/units/helpers/file_helper.php =================================================================== diff -u -r14699 -r14868 --- branches/5.2.x/core/units/helpers/file_helper.php (.../file_helper.php) (revision 14699) +++ branches/5.2.x/core/units/helpers/file_helper.php (.../file_helper.php) (revision 14868) @@ -1,6 +1,6 @@ $field_value) { - if (!is_array($field_value)) continue; + if ( !is_array($field_value) ) { + continue; + } - if (isset($field_value['upload']) && ($field_value['error'] == UPLOAD_ERR_NO_FILE)) { + if ( isset($field_value['upload']) && ($field_value['error'] == UPLOAD_ERR_NO_FILE) ) { // this is upload field, but nothing was uploaded this time unset($field_values[$field_name]); } @@ -425,9 +427,17 @@ { $parts = pathinfo($name); $ext = '.' . $parts['extension']; - $filename = mb_substr($parts['basename'], 0, -mb_strlen($ext)); + $filename = $parts['filename']; $new_name = $filename . $ext; + if ( $parts['dirname'] != '.' ) { + $path = rtrim($path, '/') . '/' . ltrim($parts['dirname'], '/'); + } + + // make sure target folder always exists, especially for cases, + // when storage engine folder is supplied as a part of $name + $this->CheckFolder($path); + while ( file_exists($path . '/' . $new_name) || in_array(rtrim($path, '/') . '/' . $new_name, $forbidden_names) ) { if ( preg_match('/(' . preg_quote($filename, '/') . '_)([0-9]*)(' . preg_quote($ext, '/') . ')/', $new_name, $regs) ) { $new_name = $regs[1] . ($regs[2] + 1) . $regs[3]; @@ -437,6 +447,10 @@ } } + if ( $parts['dirname'] != '.' ) { + $new_name = $parts['dirname'] . '/' . $new_name; + } + return $new_name; } } \ No newline at end of file