check_upload_size() - WordPress 函数参考中文文档

返回介绍

check_upload_size()

发布于 2017-09-10 字数2528 浏览 1087 评论 0

check_upload_size( array $file )

Determine if uploaded file exceeds space quota.


描述


参数

$file

(array)
(Required)
$_FILES array for a given file.


返回值

(array) $_FILES array with ‘error’ key set if file exceeds quota. ‘error’ is empty otherwise.


源代码

File: wp-admin/includes/ms.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;
}

更新日志

Version 描述
3.0.0 Introduced.

相关函数

Uses

  • wp-includes/load.php:
    wp_doing_ajax()
  • wp-admin/includes/ms.php:
    upload_is_user_over_quota()
  • wp-includes/l10n.php:
    __()
  • wp-includes/functions.php:
    wp_die()
  • wp-includes/option.php:
    get_site_option()
  • wp-includes/ms-functions.php:
    get_upload_space_available()
  • Show 1 more use
    Hide more uses


User Contributed Notes

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!