Back to Utility class

Method getMaxUploadSize

public static mixed
getMaxUploadSize
(mixed $custom = null)
Method to get the maximum allowed file size for the HTTP uploads based on the active PHP configuration
Parameters
  • mixed $custom A custom upper limit, if the PHP settings are all above this then this will be used
Returns
  • mixed Size in number of bytes
Since
  • 3.7.0
Class: Utility
Project: Joomla

Method getMaxUploadSize - Source code

/**
 * Method to get the maximum allowed file size for the HTTP uploads based on the active PHP configuration
 *
 * @param   mixed  $custom  A custom upper limit, if the PHP settings are all above this then this will be used
 *
 * @return  mixed  Size in number of bytes
 *
 * @since   3.7.0
 */
public static function getMaxUploadSize($custom = null)
{
    if ($custom) {
        $custom = HTMLHelper::_('number.bytes', $custom, '');
        if ($custom > 0) {
            $sizes[] = $custom;
        }
    }
    /*
     * Read INI settings which affects upload size limits
     * and Convert each into number of bytes so that we can compare
     */
    $sizes[] = HTMLHelper::_('number.bytes', ini_get('post_max_size'), '');
    $sizes[] = HTMLHelper::_('number.bytes', ini_get('upload_max_filesize'), '');
    // The minimum of these is the limiting factor
    return min($sizes);
}