Skip to content

Commit

Permalink
Support attaching multiple files with same name
Browse files Browse the repository at this point in the history
Fixes #19683
  • Loading branch information
vboctor committed May 2, 2015
1 parent 5ee4075 commit 40074fa
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions core/file_api.php
Expand Up @@ -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();
Expand Down

0 comments on commit 40074fa

Please sign in to comment.