Index: branches/5.2.x/core/kernel/startup.php =================================================================== diff -u -N -r16435 -r16633 --- branches/5.2.x/core/kernel/startup.php (.../startup.php) (revision 16435) +++ branches/5.2.x/core/kernel/startup.php (.../startup.php) (revision 16633) @@ -1,6 +1,6 @@ cacheManager = $this->makeClass('kCacheManager'); $this->cacheManager->InitCache(); + define('MAX_UPLOAD_SIZE', $this->getMaxUploadSize()); + if ( defined('DEBUG_MODE') && $this->isDebugMode() ) { $this->Debugger->appendTimestamp('Before UnitConfigReader'); } @@ -394,6 +396,36 @@ } /** + * Calculates maximal upload file size + * + * @return integer + */ + protected function getMaxUploadSize() + { + $cache_key = 'max_upload_size'; + $max_upload_size = $this->getCache($cache_key); + + if ( $max_upload_size === false ) { + $max_upload_size = kUtil::parseIniSize(ini_get('upload_max_filesize')); + $post_max_size = ini_get('post_max_size'); + + if ( $post_max_size !== '0' ) { + $max_upload_size = min($max_upload_size, kUtil::parseIniSize($post_max_size)); + } + + $memory_limit = ini_get('memory_limit'); + + if ( $memory_limit !== '-1' ) { + $max_upload_size = min($max_upload_size, kUtil::parseIniSize($memory_limit)); + } + + $this->setCache($cache_key, $max_upload_size); + } + + return $max_upload_size; + } + + /** * Performs initialization of manager classes, that can be overridden from unit configs * * @return void Index: branches/5.2.x/core/kernel/globals.php =================================================================== diff -u -N -r16535 -r16633 --- branches/5.2.x/core/kernel/globals.php (.../globals.php) (revision 16535) +++ branches/5.2.x/core/kernel/globals.php (.../globals.php) (revision 16633) @@ -1,6 +1,6 @@