function file_validate_size


Error message

User warning: The following module is missing from the file system: theme/theme. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1156 of /var/www/html/elmsln_community/
cis7 file_validate_size(stdClass $file, $file_limit = 0, $user_limit = 0)
cle7 file_validate_size(stdClass $file, $file_limit = 0, $user_limit = 0)
elmsmedia7 file_validate_size(stdClass $file, $file_limit = 0, $user_limit = 0)
icor7 file_validate_size(stdClass $file, $file_limit = 0, $user_limit = 0)
meedjum_blog7 file_validate_size(stdClass $file, $file_limit = 0, $user_limit = 0)
mooc7 file_validate_size(stdClass $file, $file_limit = 0, $user_limit = 0)

Checks that the file's size is below certain limits.

This check is not enforced for the user #1.


$file: A Drupal file object.

$file_limit: An integer specifying the maximum file size in bytes. Zero indicates that no limit should be enforced.

$user_limit: An integer specifying the maximum number of bytes the user is allowed. Zero indicates that no limit should be enforced.

Return value

An array. If the file size exceeds limits, it will contain an error message.

See also


Related topics

6 string references to 'file_validate_size'
cis_helper_quick_setup_page in profiles/cis/modules/custom/cis_helper/
Callback for quick setup page to build a lot of elements at once.
file_entity_get_upload_validators in sites/all/modules/ulmus/file_entity/
Retrieves the upload validators for a file.
file_field_widget_upload_validators in modules/file/
Retrieves the upload validators for a file field.
theme_file_upload_help in modules/file/
Returns HTML for help text based on file upload validators.
user_validate_picture in modules/user/user.module
Validates an image uploaded by a user.

... See full list


includes/, line 1743
API for handling file uploads and server file management.


function file_validate_size(stdClass $file, $file_limit = 0, $user_limit = 0) {
  global $user;

  $errors = array();

  // Bypass validation for uid  = 1.
  if ($user->uid != 1) {
    if ($file_limit && $file->filesize > $file_limit) {
      $errors[] = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size($file->filesize), '%maxsize' => format_size($file_limit)));

    // Save a query by only calling file_space_used() when a limit is provided.
    if ($user_limit && (file_space_used($user->uid) + $file->filesize) > $user_limit) {
      $errors[] = t('The file is %filesize which would exceed your disk quota of %quota.', array('%filesize' => format_size($file->filesize), '%quota' => format_size($user_limit)));
  return $errors;



Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/ in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/
The website encountered an unexpected error. Please try again later.