/**
* Basic setup.
*/
- public function preProcess() {
- // check for post max size
- CRM_Utils_Number::formatUnitSize(ini_get('post_max_size'), TRUE);
+ public function preProcess(): void {
+ $maxImportFileSize = CRM_Utils_Number::formatUnitSize(ini_get('upload_max_filesize'));
+ $postMaxSize = CRM_Utils_Number::formatUnitSize(ini_get('post_max_size'));
+ if ($maxImportFileSize > $postMaxSize) {
+ 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");
+ }
+
// This is a temp hack for the fact we really don't need to hard-code each setting in the tpl but
// we haven't worked through NOT doing that. These settings have been un-hardcoded.
$this->assign('pure_config_settings', [
$errors = [];
// validate max file size
- $iniBytes = CRM_Utils_Number::formatUnitSize(ini_get('upload_max_filesize'), FALSE);
- $inputBytes = CRM_Utils_Number::formatUnitSize($fields['maxFileSize'] . 'M', FALSE);
+ $iniBytes = CRM_Utils_Number::formatUnitSize(ini_get('upload_max_filesize'));
+ $inputBytes = ((int) $fields['maxFileSize']) * 1024 * 1024;
if ($inputBytes > $iniBytes) {
$errors['maxFileSize'] = ts("Maximum file size cannot exceed limit defined in \"php.ini\" (\"upload_max_filesize=%1\").", [
// Assign maxAttachments count to template for help message
$form->assign('maxAttachments', $numAttachments);
- $config = CRM_Core_Config::singleton();
// set default max file size as 2MB
- $maxFileSize = $config->maxFileSize ? $config->maxFileSize : 2;
+ $maxFileSize = \Civi::settings()->get('maxFileSize') ?: 2;
$currentAttachmentInfo = self::getEntityFile($entityTable, $entityID, TRUE);
$totalAttachments = $currentAttachmentInfo ? count($currentAttachmentInfo) : 0;
public function buildQuickForm(&$form) {
$form->add('hidden', 'hidden_dataSource', 'CRM_Import_DataSource_CSV');
- $uploadFileSize = CRM_Utils_Number::formatUnitSize(Civi::settings()->get('maxFileSize') . 'm', TRUE);
+ $uploadFileSize = $uploadSize = \Civi::settings()->get('maxFileSize');
//Fetch uploadFileSize from php_ini when $config->maxFileSize is set to "no limit".
if (empty($uploadFileSize)) {
- $uploadFileSize = CRM_Utils_Number::formatUnitSize(ini_get('upload_max_filesize'), TRUE);
+ $uploadFileSize = CRM_Utils_Number::formatUnitSize(ini_get('upload_max_filesize'));
+ $uploadSize = round(($uploadFileSize / (1024 * 1024)), 2);
}
- $uploadSize = round(($uploadFileSize / (1024 * 1024)), 2);
$form->assign('uploadSize', $uploadSize);
$form->add('File', 'uploadFile', ts('Import Data File'), NULL, TRUE);
$form->add('text', 'fieldSeparator', ts('Import Field Separator'), ['size' => 2], TRUE);
*/
public function preProcess(): void {
$this->pushUrlToUserContext();
- // check for post max size
- CRM_Utils_Number::formatUnitSize(ini_get('post_max_size'), TRUE);
$this->assign('importEntity', $this->getTranslatedEntity());
$this->assign('importEntities', $this->getTranslatedEntities());
}
}
/**
- * Some kind of numbery-looky-printy thing.
+ * Convert a file size value from the formats allowed in php_ini to the number of bytes.
*
* @param string $size
- * @param bool $checkForPostMax
*
* @return int
*/
- public static function formatUnitSize($size, $checkForPostMax = FALSE) {
+ public static function formatUnitSize($size): int {
if ($size) {
$last = strtolower($size[strlen($size) - 1]);
$size = (int) $size;
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.", [1 => CRM_Utils_System::url('civicrm/admin/setting/misc', 'reset=1')]), ts("Warning"), "alert");
- }
- }
return $size;
}
}