check_upload_size

Determine if uploaded file exceeds space quota.

Description

(array) check_upload_size( (array) $file ); 

Returns (array)

$_FILES array with 'error' key set if file exceeds quota. 'error' is empty otherwise.

Parameters (1)

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

Usage

  1. if ( !function_exists( 'check_upload_size' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/ms.php'; 
  3.  
  4. // $_FILES array for a given file. 
  5. $file = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = check_upload_size($file); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/ms.php  
  1. function check_upload_size( $file ) { 
  2. if ( get_site_option( 'upload_space_check_disabled' ) ) 
  3. return $file; 
  4.  
  5. if ( $file[error] != '0' ) // there's already an error 
  6. return $file; 
  7.  
  8. if ( defined( 'WP_IMPORTING' ) ) 
  9. return $file; 
  10.  
  11. $space_left = get_upload_space_available(); 
  12.  
  13. $file_size = filesize( $file['tmp_name'] ); 
  14. if ( $space_left < $file_size ) { 
  15. /** translators: 1: Required disk space in kilobytes */ 
  16. $file[error] = sprintf( __( 'Not enough space to upload. %1$s KB needed.' ), number_format( ( $file_size - $space_left ) / KB_IN_BYTES ) ); 
  17.  
  18. if ( $file_size > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) { 
  19. /** translators: 1: Maximum allowed file size in kilobytes */ 
  20. $file[error] = sprintf( __( 'This file is too big. Files must be less than %1$s KB in size.' ), get_site_option( 'fileupload_maxk', 1500 ) ); 
  21.  
  22. if ( upload_is_user_over_quota( false ) ) { 
  23. $file[error] = __( 'You have used your space quota. Please delete files before uploading.' ); 
  24.  
  25. if ( $file[error] != '0' && ! isset( $_POST['html-upload'] ) && ! wp_doing_ajax() ) { 
  26. wp_die( $file[error] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' ); 
  27.  
  28. return $file;