check_upload_size()
最后更新于:2021-11-25 20:31:10
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.
源文件
文件: gc-admin/includes/ms.php
function check_upload_size( $file ) {
if ( get_site_option( 'upload_space_check_disabled' ) ) {
return $file;
}
if ( '0' != $file['error'] ) { // There's already an error.
return $file;
}
if ( defined( 'GC_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 ( '0' != $file['error'] && ! isset( $_POST['html-upload'] ) && ! gc_doing_ajax() ) {
gc_die( $file['error'] . ' <a href="https://docs.gechiui.com/functions/check_upload_size/history.go(-1)">' . __( 'Back' ) . '</a>' );
}
return $file;
}