From 40074fa9ea96a1f369471c4dc8cc7ddedc7b35af Mon Sep 17 00:00:00 2001 From: Victor Boctor Date: Thu, 30 Apr 2015 22:39:02 -0700 Subject: [PATCH] Support attaching multiple files with same name Fixes #19683 --- core/file_api.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/core/file_api.php b/core/file_api.php index 6d1a3a5af1..e4ede6883b 100644 --- a/core/file_api.php +++ b/core/file_api.php @@ -641,8 +641,19 @@ function file_add( $p_bug_id, array $p_file, $p_table = 'bug', $p_title = '', $p trigger_error( ERROR_FILE_NOT_ALLOWED, ERROR ); } - if( !file_is_name_unique( $t_file_name, $p_bug_id ) ) { - trigger_error( ERROR_FILE_DUPLICATE, ERROR ); + $t_org_filename = $t_file_name; + $t_suffix_id = 1; + + while( !file_is_name_unique( $t_file_name, $p_bug_id ) ) { + $t_suffix_id++; + + $t_dot_index = strripos( $t_org_filename, '.' ); + if( $t_dot_index === false ) { + $t_file_name = $t_org_filename . '-' . $t_suffix_id; + } else { + $t_extension = substr( $t_org_filename, $t_dot_index, strlen( $t_org_filename ) - $t_dot_index ); + $t_file_name = substr( $t_org_filename, 0, $t_dot_index ) . '-' . $t_suffix_id . $t_extension; + } } antispam_check();