Skip to content

Commit

Permalink
Implement AttachmentOversized exception
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhicks committed Sep 17, 2011
1 parent 755b08b commit 8bbb809
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
13 changes: 13 additions & 0 deletions application/MantisBT/Exception/Attachment/AttachmentOversized.php
@@ -0,0 +1,13 @@
<?php
namespace MantisBT\Exception\Attachment;
use MantisBT\Exception\ExceptionAbstract;

require_api('lang_api.php');

class AttachmentOversized extends ExceptionAbstract {
public function __construct() {
$errorMessage = lang_get(ERROR_FILE_TOO_BIG, null, false);
parent::__construct( ERROR_FILE_TOO_BIG, $errorMessage, null );
$this->responseCode = 400;
}
}
6 changes: 4 additions & 2 deletions application/core/file_api.php
Expand Up @@ -36,6 +36,8 @@
* @uses utility_api.php
*/

use MantisBT\Exception\Attachment\AttachmentOversized;

require_api( 'access_api.php' );
require_api( 'authentication_api.php' );
require_api( 'bug_api.php' );
Expand Down Expand Up @@ -666,7 +668,7 @@ function file_add( $p_bug_id, $p_file, $p_table = 'bug', $p_title = '', $p_desc
}
$t_max_file_size = (int) min( ini_get_number( 'upload_max_filesize' ), ini_get_number( 'post_max_size' ), config_get( 'max_file_size' ) );
if( $t_file_size > $t_max_file_size ) {
trigger_error( ERROR_FILE_TOO_BIG, ERROR );
throw new AttachmentOversized();
}
$c_file_size = db_prepare_int( $t_file_size );

Expand Down Expand Up @@ -811,7 +813,7 @@ function file_ensure_uploaded( $p_file ) {
switch( $p_file['error'] ) {
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
trigger_error( ERROR_FILE_TOO_BIG, ERROR );
throw new AttachmentOversized();
break;
case UPLOAD_ERR_PARTIAL:
case UPLOAD_ERR_NO_FILE:
Expand Down

0 comments on commit 8bbb809

Please sign in to comment.