Index: branches/5.2.x/core/units/helpers/file_helper.php =================================================================== diff -u -N -r14868 -r14896 --- branches/5.2.x/core/units/helpers/file_helper.php (.../file_helper.php) (revision 14868) +++ branches/5.2.x/core/units/helpers/file_helper.php (.../file_helper.php) (revision 14896) @@ -1,6 +1,6 @@ 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]; + do { + if ( preg_match('/(.*)_([0-9]*)(' . preg_quote($ext, '/') . ')/', $new_name, $regs) ) { + $new_name = $regs[1] . '_' . ((int)$regs[2] + 1) . $regs[3]; } - else { + elseif ( $original_checked ) { $new_name = $filename . '_1' . $ext; } - } + $original_checked = true; + $res = file_exists($path . '/' . $new_name) || in_array($path . '/' . $new_name, $forbidden_names); + } while ($res !== false); + if ( $parts['dirname'] != '.' ) { $new_name = $parts['dirname'] . '/' . $new_name; }