$config = CRM_Core_Config::singleton();
$this->_uploadMaxSize = (int) ini_get('upload_max_filesize');
// check for post max size
- CRM_Core_Config_Defaults::formatUnitSize(ini_get('post_max_size'), TRUE);
+ CRM_Utils_Number::formatUnitSize(ini_get('post_max_size'), TRUE);
}
/**
// check for post max size avoid when called twice
$snippet = CRM_Utils_Array::value('snippet', $_GET, 0);
if (empty($snippet)) {
- CRM_Core_Config_Defaults::formatUnitSize(ini_get('post_max_size'), TRUE);
+ CRM_Utils_Number::formatUnitSize(ini_get('post_max_size'), TRUE);
}
while ($file = readdir($handler)) {
$this->groupTree = defined('CIVICRM_GROUPTREE') ? TRUE : FALSE;
}
- /**
- * Format size.
- *
- */
- public static function formatUnitSize($size, $checkForPostMax = FALSE) {
- if ($size) {
- $last = strtolower($size{strlen($size) - 1});
- switch ($last) {
- // The 'G' modifier is available since PHP 5.1.0
-
- case 'g':
- $size *= 1024;
- case 'm':
- $size *= 1024;
- case 'k':
- $size *= 1024;
- }
-
- if ($checkForPostMax) {
- $maxImportFileSize = self::formatUnitSize(ini_get('upload_max_filesize'));
- $postMaxSize = self::formatUnitSize(ini_get('post_max_size'));
- if ($maxImportFileSize > $postMaxSize && $postMaxSize == $size) {
- CRM_Core_Session::setStatus(ts("Note: Upload max filesize ('upload_max_filesize') should not exceed Post max size ('post_max_size') as defined in PHP.ini, please check with your system administrator."), ts("Warning"), "alert");
- }
- //respect php.ini upload_max_filesize
- if ($size > $maxImportFileSize && $size !== $postMaxSize) {
- $size = $maxImportFileSize;
- CRM_Core_Session::setStatus(ts("Note: Please verify your configuration for Maximum File Size (in MB) <a href='%1'>Administrator >> System Settings >> Misc</a>. It should support 'upload_max_size' as defined in PHP.ini.Please check with your system administrator.", array(1 => CRM_Utils_System::url('civicrm/admin/setting/misc', 'reset=1'))), ts("Warning"), "alert");
- }
- }
- return $size;
- }
- }
-
/**
* Set the default values.
* in an empty db, also called when setting component using GUI
$config = CRM_Core_Config::singleton();
- $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize . 'm', TRUE);
+ $uploadFileSize = CRM_Utils_Number::formatUnitSize($config->maxFileSize . 'm', TRUE);
$uploadSize = round(($uploadFileSize / (1024 * 1024)), 2);
$form->assign('uploadSize', $uploadSize);
$form->add('File', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url(static::PATH, $params));
// check for post max size
- CRM_Core_Config_Defaults::formatUnitSize(ini_get('post_max_size'), TRUE);
+ CRM_Utils_Number::formatUnitSize(ini_get('post_max_size'), TRUE);
}
/**
public function buildQuickForm() {
$config = CRM_Core_Config::singleton();
- $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize . 'm', TRUE);
+ $uploadFileSize = CRM_Utils_Number::formatUnitSize($config->maxFileSize . 'm', TRUE);
$uploadSize = round(($uploadFileSize / (1024 * 1024)), 2);
$this->assign('uploadSize', $uploadSize);
}
}
+ /**
+ * Some kind of numbery-looky-printy thing.
+ */
+ public static function formatUnitSize($size, $checkForPostMax = FALSE) {
+ if ($size) {
+ $last = strtolower($size{strlen($size) - 1});
+ switch ($last) {
+ // The 'G' modifier is available since PHP 5.1.0
+
+ case 'g':
+ $size *= 1024;
+ case 'm':
+ $size *= 1024;
+ case 'k':
+ $size *= 1024;
+ }
+
+ if ($checkForPostMax) {
+ $maxImportFileSize = self::formatUnitSize(ini_get('upload_max_filesize'));
+ $postMaxSize = self::formatUnitSize(ini_get('post_max_size'));
+ if ($maxImportFileSize > $postMaxSize && $postMaxSize == $size) {
+ CRM_Core_Session::setStatus(ts("Note: Upload max filesize ('upload_max_filesize') should not exceed Post max size ('post_max_size') as defined in PHP.ini, please check with your system administrator."), ts("Warning"), "alert");
+ }
+ //respect php.ini upload_max_filesize
+ if ($size > $maxImportFileSize && $size !== $postMaxSize) {
+ $size = $maxImportFileSize;
+ CRM_Core_Session::setStatus(ts("Note: Please verify your configuration for Maximum File Size (in MB) <a href='%1'>Administrator >> System Settings >> Misc</a>. It should support 'upload_max_size' as defined in PHP.ini.Please check with your system administrator.", array(1 => CRM_Utils_System::url('civicrm/admin/setting/misc', 'reset=1'))), ts("Warning"), "alert");
+ }
+ }
+ return $size;
+ }
+ }
+
}