返回介绍

check_upload_size()

发布于 2017-09-10 21:41:09 字数 2526 浏览 1208 评论 0 收藏 0

check_upload_size( array $file )

Determine if uploaded file exceeds space quota.


description


参数

$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;
}

更新日志

Versiondescription
3.0.0Introduced.

相关函数

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文