upload_is_file_too_big

函数
upload_is_file_too_big ( $upload )
参数
  • (array) $upload
    Required:
返回值
  • (string|array) If the upload is under the size limit, $upload is returned. Otherwise returns an error message.
定义位置
相关方法
upload_space_settingupload_is_user_over_quotaload_image_to_editadd_user_to_blogupload_size_limit_filter
引入
-
弃用
-

upload_is_file_too_big: 这个函数根据服务器的设置检查一个上传的文件是否过大。它通常用于验证插件或主题代码中的上传文件。

检查上传是否过大。

function upload_is_file_too_big( $upload ) {
	if ( ! is_array( $upload ) || defined( 'WP_IMPORTING' ) || get_site_option( 'upload_space_check_disabled' ) ) {
		return $upload;
	}

	if ( strlen( $upload['bits'] ) > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) {
		/* translators: %s: Maximum allowed file size in kilobytes. */
		return sprintf( __( 'This file is too big. Files must be less than %s KB in size.' ) . '<br />', get_site_option( 'fileupload_maxk', 1500 ) );
	}

	return $upload;
}

常见问题

FAQs
查看更多 >