Advertisements

check_upload_size

Definition:
function check_upload_size( $file ) {}

Determine if uploaded file exceeds space quota.

Parameters

  • array $file: $_FILES array for a given file.

Return values

returns:array with ‘error’ key set if file exceeds quota. ‘error’ is empty otherwise.

Source code

function check_upload_size( $file ) {

	if ( get_site_option( 'upload_space_check_disabled' ) )

		return $file;



	if ( $file['error'] != '0' ) // there's already an error

		return $file;



	if ( defined( 'WP_IMPORTING' ) )

		return $file;



	$space_allowed = 1048576 * get_space_allowed();

	$space_used = get_dirsize( BLOGUPLOADDIR );

	$space_left = $space_allowed - $space_used;

	$file_size = filesize( $file['tmp_name'] );

	if ( $space_left < $file_size )

		$file['error'] = sprintf( __( 'Not enough space to upload. %1$s KB needed.' ), number_format( ($file_size - $space_left) /1024 ) );

	if ( $file_size > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) )

		$file['error'] = sprintf(__('This file is too big. Files must be less than %1$s KB in size.'), get_site_option( 'fileupload_maxk', 1500 ) );

	if ( upload_is_user_over_quota( false ) ) {

		$file['error'] = __( 'You have used your space quota. Please delete files before uploading.' );

	}

	if ( $file['error'] != '0' && !isset($_POST['html-upload']) )

		wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' );



	return $file;

}

611

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: