8.5.x file.inc file_upload_max_size()
8.0.x file.inc file_upload_max_size()
8.1.x file.inc file_upload_max_size()
8.2.x file.inc file_upload_max_size()
8.3.x file.inc file_upload_max_size()
8.4.x file.inc file_upload_max_size()
8.6.x file.inc file_upload_max_size()
4.7.x file.inc file_upload_max_size()
5.x file.inc file_upload_max_size()
6.x file.inc file_upload_max_size()
7.x file.inc file_upload_max_size()

Determine the maximum file upload size by querying the PHP settings.

Return value

A file size limit in MB based on the PHP upload_max_filesize and post_max_size

Related topics

2 calls to file_upload_max_size()
upload_settings in modules/upload.module
upload_settings_form_validate in modules/upload.module
Form API callback to validate the upload settings form.

File

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

Code

function file_upload_max_size() {
  static $max_size = -1;
  if ($max_size < 0) {
    $upload_max = _file_convert_to_mb(ini_get('upload_max_filesize'));

    // sanity check- a single upload should not be more than 50% the size limit of the total post
    $post_max = _file_convert_to_mb(ini_get('post_max_size')) / 2;
    $max_size = $upload_max < $post_max ? $upload_max : $post_max;
  }
  return $max_size;
}