On this page
check_upload_size( array $file ): array
Determine if uploaded file exceeds space quota.
Parameters
$filearray Required-
An element from the
$_FILESarray for a given file.
Return
array The $_FILES array element with 'error' key set if file exceeds quota. 'error' is empty otherwise.
Source
File: wp-admin/includes/ms.php. View all references
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: %s: Required disk space in kilobytes. */
$file['error'] = sprintf( __( 'Not enough space to upload. %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: %s: Maximum allowed file size in kilobytes. */
$file['error'] = sprintf( __( 'This file is too big. Files must be less than %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;
}
Related
Uses
| Uses | Description |
|---|---|
| wp_doing_ajax() wp-includes/load.php | Determines whether the current request is a WordPress Ajax request. |
| upload_is_user_over_quota() wp-admin/includes/ms.php | Check whether a site has used its allotted upload space. |
| get_upload_space_available() wp-includes/ms-functions.php | Determines if there is any upload space left in the current blog’s quota. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| wp_die() wp-includes/functions.php | Kills WordPress execution and displays HTML page with an error message. |
| get_site_option() wp-includes/option.php | Retrieve an option value for the current network based on name of option. |
Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/check_upload_size