Skip to content

Commit

Permalink
Add multiple file upload functionality
Browse files Browse the repository at this point in the history
Adds a new option in config_defaults_inc.php (file_upload_max_num) to
determine how many files can be simultaneously uploaded.

Modifies the code in issue reporting and view details pages, to enable
the new functionality.

Fixes #5228
  • Loading branch information
dregad authored and rombert committed Mar 25, 2012
1 parent 4618dcd commit 4599c5b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
21 changes: 16 additions & 5 deletions bug_file_add.php
Expand Up @@ -25,14 +25,14 @@
/**
* MantisBT Core API's
*/
require_once( 'core.php' );

require_once( 'core.php' );
require_once( 'file_api.php' );

$f_bug_id = gpc_get_int( 'bug_id', -1 );
$f_file = gpc_get_file( 'file', -1 );
$f_bug_id = gpc_get_int( 'bug_id', -1 );
$f_files = gpc_get_file( 'ufile', -1 );

if ( $f_bug_id == -1 && $f_file == -1 ) {
if ( $f_bug_id == -1 && $f_files == -1 ) {
# _POST/_FILES does not seem to get populated if you exceed size limit so check if bug_id is -1
trigger_error( ERROR_FILE_TOO_BIG, ERROR );
}
Expand All @@ -52,7 +52,18 @@

access_ensure_bug_level( config_get( 'upload_bug_file_threshold' ), $f_bug_id );

file_add( $f_bug_id, $f_file, 'bug' );
// Process array of files to upload
for( $i = 0; $i < count( $f_files ); $i++ ) {
if( !empty( $f_files['name'][$i] ) ) {
$t_file['name'] = $f_files['name'][$i];
$t_file['tmp_name'] = $f_files['tmp_name'][$i];
$t_file['type'] = $f_files['type'][$i];
$t_file['error'] = $f_files['error'][$i];
$t_file['size'] = $f_files['size'][$i];

file_add( $f_bug_id, $t_file, 'bug' );
}
}

form_security_purge( 'bug_file_add' );

Expand Down
13 changes: 12 additions & 1 deletion bug_file_upload_inc.php
Expand Up @@ -56,7 +56,18 @@
<td width="85%">
<input type="hidden" name="bug_id" value="<?php echo $f_bug_id ?>" />
<input type="hidden" name="max_file_size" value="<?php echo $t_max_file_size ?>" />
<input name="file" type="file" size="40" />
<?php
// Display multiple file upload fields
$t_file_upload_max_num = max( 1, config_get( 'file_upload_max_num' ) );
for( $i = 0; $i < $t_file_upload_max_num; $i++ ) {
?>
<input id="ufile[]" name="ufile[]" type="file" size="50" />
<?php
if( $t_file_upload_max_num > 1 ) {
echo '<br />';
}
}
?>
<input type="submit" class="button" value="<?php echo lang_get( 'upload_file_button' ) ?>" />
</td>
</tr>
Expand Down
6 changes: 6 additions & 0 deletions config_defaults_inc.php
Expand Up @@ -1567,6 +1567,12 @@
*/
$g_file_upload_ftp_pass = 'readwritepass';

/**
* Maximum number of files that can be uploaded simultaneously
* @global int $g_file_upload_max_num
*/
$g_file_upload_max_num = 1;

/**
* Maximum file size that can be uploaded
* Also check your PHP settings (default is usually 2MBs)
Expand Down

0 comments on commit 4599c5b

Please sign in to comment.