Index: branches/5.2.x/core/kernel/application.php =================================================================== --- branches/5.2.x/core/kernel/application.php +++ branches/5.2.x/core/kernel/application.php @@ -306,6 +306,8 @@ $this->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 =================================================================== --- branches/5.2.x/core/kernel/globals.php +++ branches/5.2.x/core/kernel/globals.php @@ -997,6 +997,33 @@ } } + /** + * Parse ini size + * + * @param string $size Size. + * + * @return integer + */ + public static function parseIniSize($size) + { + $result = (int)$size; + $size = strtolower($size); + + if ( strpos($size, 'k') ) { + return $result * 1024; + } + + if ( strpos($size, 'm') ) { + return $result * 1024 * 1024; + } + + if ( strpos($size, 'g') ) { + return $result * 1024 * 1024 * 1024; + } + + return $result; + } + } /** Index: branches/5.2.x/core/kernel/startup.php =================================================================== --- branches/5.2.x/core/kernel/startup.php +++ branches/5.2.x/core/kernel/startup.php @@ -114,7 +114,6 @@ define('IMAGES_PATH', WRITEBALE_BASE . '/images/'); define('IMAGES_PENDING_PATH', IMAGES_PATH . 'pending/'); - define('MAX_UPLOAD_SIZE', min(ini_get('upload_max_filesize'), ini_get('post_max_size'))*1024*1024); define('EDITOR_PATH', $vars['EditorPath']);