Welcome, Guest
Username: Password: Remember me

TOPIC: [FIXED] Improved function "getMaxSize"

Improved function "getMaxSize" 14 Aug 2013 08:56 #10775

  • Tomaselli
  • Tomaselli's Avatar
  • Online
  • Elite Member
  • Posts: 293
  • Thank you received: 87
  • Karma: 46
The function getMaxSize located in COMPONENT\classes\file\upload.php, doesn't consider the server variable upload_max_filesize.
Sometimes the component config variable "upload_maxsize" is bigger than the previous server variable, so it happens to give a wrong info to the user at the upload process. I think the server variable upload_max_filesize should be considered as well, so here my hack to do it:
	public static function getMaxSize($string = false, $maxSizeCustom = null)
	{
		$config	= JComponentHelper::getParams( 'com_component' );

		$maxSize = (int)$config->get('upload_maxsize') * 1024 * 1024;
		$phpMaxSize = intval(ini_get('upload_max_filesize')) * 1024 * 1024; /* hack */
		
		if (!$maxSize)
			$maxSize =COMPONENT_UPLOAD_DEFAULT_MAX_SIZE;
			
		if ($maxSizeCustom)
			$maxSize = min($maxSize, $maxSizeCustom);

		$maxSize = min($maxSize, $phpMaxSize); /* hack */

		if ($string)
			$maxSize = JText::sprintf("COMPONENT_UPLOAD_MAX_B", self::bytesToString($maxSize));

		return $maxSize;
	}

this also solve an unexpected script exit with no warning, I encountered during the upload of big files not allowed by the server.
Last Edit: 14 Aug 2013 09:00 by Tomaselli.
The administrator has disabled public write access.
The following user(s) said Thank You: admin

Improved function "getMaxSize" 18 Aug 2013 20:01 #10810

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Fixed.
Thank you.

K+.
Coding is now a piece of cake
The administrator has disabled public write access.
Time to create page: 0.059 seconds

Get Started