Skip to content

Commit

Permalink
Fix dropzone max file size setting
Browse files Browse the repository at this point in the history
The maximum file size for uploads can be affected by both mantis
configuration and php settings.
Fix the setting of max size in dropzone object with the actual max size.

Encapsulate the method of calculation and refactor usages of
'max_file_size'.

Fixes: #25463
  • Loading branch information
cproensa authored and atrol committed Feb 24, 2019
1 parent 3965532 commit 613e885
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion api/soap/mc_file_api.php
Expand Up @@ -85,7 +85,7 @@ function mci_file_add( $p_id, $p_name, $p_content, $p_file_type, $p_table, $p_ti
}

$t_file_size = strlen( $p_content );
$t_max_file_size = (int)min( ini_get_number( 'upload_max_filesize' ), ini_get_number( 'post_max_size' ), config_get( 'max_file_size' ) );
$t_max_file_size = file_get_max_file_size();
if( $t_file_size > $t_max_file_size ) {
return ApiObjectFactory::faultBadRequest( 'File is too big. Max size is "' . $t_max_file_size . '" bytes.' );
}
Expand Down
2 changes: 1 addition & 1 deletion bug_report_page.php
Expand Up @@ -622,7 +622,7 @@
<?php
# File Upload (if enabled)
if( $t_show_attachments ) {
$t_max_file_size = (int)min( ini_get_number( 'upload_max_filesize' ), ini_get_number( 'post_max_size' ), config_get( 'max_file_size' ) );
$t_max_file_size = file_get_max_file_size();
$t_file_upload_max_num = max( 1, config_get( 'file_upload_max_num' ) );
?>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion bugnote_add_inc.php
Expand Up @@ -144,7 +144,7 @@

if( $t_allow_file_upload ) {
$t_file_upload_max_num = max( 1, config_get( 'file_upload_max_num' ) );
$t_max_file_size = (int)min( ini_get_number( 'upload_max_filesize' ), ini_get_number( 'post_max_size' ), config_get( 'max_file_size' ) );
$t_max_file_size = file_get_max_file_size();

$t_attach_style = ( $t_default_bugnote_view_status != VS_PUBLIC ) ? 'display: none;' : '';
?>
Expand Down
2 changes: 1 addition & 1 deletion config_defaults_inc.php
Expand Up @@ -1891,7 +1891,7 @@
$g_attachments_file_permissions = 0400;

/**
* Maximum file size that can be uploaded
* Maximum file size (bytes) that can be uploaded.
* Also check your PHP settings (default is usually 2MBs)
* @global integer $g_max_file_size
*/
Expand Down
9 changes: 9 additions & 0 deletions core/file_api.php
Expand Up @@ -1247,3 +1247,12 @@ function file_get_content_type_override( $p_filename ) {

return null;
}

/**
* Return the maximum file size that can be uploaded, based on mantis and php
* configured setting.
* @return integer File size in bytes
*/
function file_get_max_file_size() {
return (int)min( ini_get_number( 'upload_max_filesize' ), ini_get_number( 'post_max_size' ), config_get( 'max_file_size' ) );
}
3 changes: 2 additions & 1 deletion core/print_api.php
Expand Up @@ -2077,8 +2077,9 @@ function print_max_filesize( $p_size, $p_divider = 1000, $p_unit = 'kb' ) {
* @return void
*/
function print_dropzone_form_data() {
$t_max_file_size = ceil( file_get_max_file_size() / ( 1024*1024 ) );
echo 'data-force-fallback="' . ( config_get( 'dropzone_enabled' ) ? 'false' : 'true' ) . '"' . "\n";
echo "\t" . 'data-max-filesize="'. ceil( config_get( 'max_file_size' ) / (1000 * 1024) ) . '"' . "\n";
echo "\t" . 'data-max-filesize="'. $t_max_file_size . '"' . "\n";
$t_allowed_files = config_get( 'allowed_files' );
if ( !empty ( $t_allowed_files ) ) {
$t_allowed_files = '.' . implode ( ',.', explode ( ',', config_get( 'allowed_files' ) ) );
Expand Down
6 changes: 1 addition & 5 deletions plugins/XmlImportExport/pages/import.php
Expand Up @@ -33,11 +33,7 @@
$t_this_page = plugin_page( 'import' ); # FIXME with plugins this does not work...
print_manage_menu( $t_this_page );

$t_max_file_size = (int)min(
ini_get_number( 'upload_max_filesize' ),
ini_get_number( 'post_max_size' ),
config_get( 'max_file_size' )
);
$t_max_file_size = file_get_max_file_size();

# We need a project to import into
$t_project_id = helper_get_current_project( );
Expand Down
2 changes: 1 addition & 1 deletion proj_doc_add_page.php
Expand Up @@ -50,7 +50,7 @@

access_ensure_project_level( config_get( 'upload_project_file_threshold' ) );

$t_max_file_size = (int)min( ini_get_number( 'upload_max_filesize' ), ini_get_number( 'post_max_size' ), config_get( 'max_file_size' ) );
$t_max_file_size = file_get_max_file_size();

layout_page_header();

Expand Down
2 changes: 1 addition & 1 deletion proj_doc_edit_page.php
Expand Up @@ -70,7 +70,7 @@
$v_title = string_attribute( $v_title );
$v_description = string_textarea( $v_description );

$t_max_file_size = (int)min( ini_get_number( 'upload_max_filesize' ), ini_get_number( 'post_max_size' ), config_get( 'max_file_size' ) );
$t_max_file_size = file_get_max_file_size();

layout_page_header();

Expand Down
2 changes: 1 addition & 1 deletion proj_doc_update.php
Expand Up @@ -87,7 +87,7 @@

# prepare variables for insertion
$t_file_size = filesize( $f_file['tmp_name'] );
$t_max_file_size = (int)min( ini_get_number( 'upload_max_filesize' ), ini_get_number( 'post_max_size' ), config_get( 'max_file_size' ) );
$t_max_file_size = file_get_max_file_size();
if( $t_file_size > $t_max_file_size ) {
trigger_error( ERROR_FILE_TOO_BIG, ERROR );
}
Expand Down

0 comments on commit 613e885

Please sign in to comment.