确定上载的文件是否超出空间配额。

原型

check_upload_size( array $file )

参数

$file (array) (Required) 给定文件的$ _FILES数组。

返回值

(array)  如果文件超出配额,则设置’_FILES数组并设置’错误’键。否则’错误’是空的。

源文件

路径:wp-admin/includes/ms.php

<?php
...
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_left = get_upload_space_available();
	$file_size = filesize( $file['tmp_name'] );
	if ( $space_left < $file_size ) {
		/* translators: 1: Required disk space in kilobytes */
		$file['error'] = sprintf( __( 'Not enough space to upload. %1$s KB needed.' ), number_format( ( $file_size - $space_left ) / KB_IN_BYTES ) );
	}
	if ( $file_size > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) {
		/* translators: 1: Maximum allowed file size in kilobytes */
		$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_doing_ajax() ) {
		wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' );
	}
	return $file;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/check_upload_size/