public function preProcess() {
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/import/activity', 'reset=1'));
+ // check for post max size
+ CRM_Core_Config_Defaults::formatUnitSize(ini_get('post_max_size'), TRUE);
}
/**
public function buildQuickForm() {
//Setting Upload File Size
$config = CRM_Core_Config::singleton();
- if ($config->maxImportFileSize >= 8388608) {
+
+ $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize.'m');
+ if ($uploadFileSize >= 8388608) {
$uploadFileSize = 8388608;
}
- else {
- $uploadFileSize = $config->maxImportFileSize;
- }
$uploadSize = round(($uploadFileSize / (1024 * 1024)), 2);
$this->assign('uploadSize', $uploadSize);
-
- $this->add('file', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
-
- $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
- $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize);
$this->setMaxFileSize($uploadFileSize);
+ $this->add('File', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
+ $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize);
+ $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
$this->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File');
$this->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers'));
'checksumTimeout' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
);
+ public $_uploadMaxSize;
+
+ /**
+ * Basic setup
+ */
+
+ public function preProcess() {
+ $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);
+ }
+
/**
* Function to build the form
*
static function formRule($fields, $files, $options) {
$errors = array();
+ // validate max file size
+ if ($fields['maxFileSize'] > $options->_uploadMaxSize) {
+ $errors['maxFileSize'] = ts("Maximum file size cannot exceed Upload max size ('upload_max_filesize') as defined in PHP.ini.");
+ }
+
if (!empty($fields['wkhtmltopdfPath'])) {
// check and ensure that thi leads to the wkhtmltopdf binary
// and it is a valid executable binary
$config = CRM_Core_Config::singleton();
$params = $this->controller->exportValues($this->_name);
+ // update upload max size in DB
+ $params['maxImportFileSize'] = CRM_Core_Config_Defaults::formatUnitSize(ini_get('upload_max_filesize'));
+ CRM_Core_BAO_ConfigSetting::create($params);
+
// get current logging status
$values = $this->exportValues();
$handler = opendir($config->uploadDir);
$errorFiles = array('sqlImport.errors', 'sqlImport.conflicts', 'sqlImport.duplicates', 'sqlImport.mismatch');
+ // check for post max size
+ CRM_Core_Config_Defaults::formatUnitSize(ini_get('post_max_size'), TRUE);
+
while ($file = readdir($handler)) {
if ($file != '.' && $file != '..' &&
in_array($file, $errorFiles) && !is_writable($config->uploadDir . $file)
public function preProcess() {
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/contribute/import', 'reset=1'));
+ // check for post max size
+ CRM_Core_Config_Defaults::formatUnitSize(ini_get('post_max_size'), TRUE);
}
/**
public function buildQuickForm() {
//Setting Upload File Size
$config = CRM_Core_Config::singleton();
- if ($config->maxImportFileSize >= 8388608) {
+
+ $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize.'m');
+ if ($uploadFileSize >= 8388608) {
$uploadFileSize = 8388608;
}
- else {
- $uploadFileSize = $config->maxImportFileSize;
- }
$uploadSize = round(($uploadFileSize / (1024 * 1024)), 2);
$this->assign('uploadSize', $uploadSize);
- $this->add('file', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
-
- $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
- $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize);
+ $this->add('File', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
$this->setMaxFileSize($uploadFileSize);
+ $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize);
+ $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
$this->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File');
$this->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers'));
$this->revampPages = array();
$size = trim(ini_get('upload_max_filesize'));
+ if ($size) {
+ $this->maxImportFileSize = self::formatUnitSize($size);
+ }
+ }
+
+ /**
+ * Function to format size
+ *
+ * @access public
+ * @static
+ */
+
+ public static function formatUnitSize($size, $checkForPostMax = FALSE) {
if ($size) {
$last = strtolower($size{strlen($size) - 1});
switch ($last) {
case 'k':
$size *= 1024;
}
- $this->maxImportFileSize = $size;
+
+ if ($checkForPostMax) {
+ $config = CRM_Core_Config::singleton();
+ if($config->maxImportFileSize > $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");
+ }
+ }
+ return $size;
}
}
$params = "reset=1";
}
$session->pushUserContext(CRM_Utils_System::url('civicrm/import/custom', $params));
+
+ // check for post max size
+ CRM_Core_Config_Defaults::formatUnitSize(ini_get('post_max_size'), TRUE);
}
/**
//Setting Upload File Size
$config = CRM_Core_Config::singleton();
- if ($config->maxImportFileSize >= 8388608) {
+
+ $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize.'m');
+ if ($uploadFileSize >= 8388608) {
$uploadFileSize = 8388608;
}
- else {
- $uploadFileSize = $config->maxImportFileSize;
- }
$uploadSize = round(($uploadFileSize / (1024 * 1024)), 2);
$this->assign('uploadSize', $uploadSize);
- $this->add('file', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
-
- $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
- $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize);
+ $this->add('File', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
$this->setMaxFileSize($uploadFileSize);
+ $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize);
+ $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
$this->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File');
$this->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers'));
public function preProcess() {
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/event/import', 'reset=1'));
+ // check for post max size
+ CRM_Core_Config_Defaults::formatUnitSize(ini_get('post_max_size'), TRUE);
}
/**
public function buildQuickForm() {
//Setting Upload File Size
$config = CRM_Core_Config::singleton();
- if ($config->maxImportFileSize >= 8388608) {
+
+ $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize.'m');
+ if ($uploadFileSize >= 8388608) {
$uploadFileSize = 8388608;
}
- else {
- $uploadFileSize = $config->maxImportFileSize;
- }
$uploadSize = round(($uploadFileSize / (1024 * 1024)), 2);
$this->assign('uploadSize', $uploadSize);
- $this->add('file', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
-
- $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
- $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize);
+ $this->add('File', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
$this->setMaxFileSize($uploadFileSize);
+ $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize);
+ $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
$this->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File');
$this->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers'));
$config = CRM_Core_Config::singleton();
// FIXME: why do we limit the file size to 8 MiB if it's larger in config?
- $uploadFileSize = $config->maxImportFileSize >= 8388608 ? 8388608 : $config->maxImportFileSize;
+ $sizeInBytes = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize.'m');
+ $uploadFileSize = $sizeInBytes >= 8388608 ? 8388608 : $sizeInBytes;
$uploadSize = round(($uploadFileSize / (1024 * 1024)), 2);
$form->assign('uploadSize', $uploadSize);
- $form->add('file', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
-
+ $form->add('File', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
$form->setMaxFileSize($uploadFileSize);
$form->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize);
$form->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File');
*/
function postProcess(&$params, &$db, &$form) {
$file = $params['uploadFile']['name'];
-
$result = self::_CsvToTable($db,
$file,
CRM_Utils_Array::value('skipColumnHeader', $params, FALSE),
public function preProcess() {
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/member/import', 'reset=1'));
+ // check for post max size
+ CRM_Core_Config_Defaults::formatUnitSize(ini_get('post_max_size'), TRUE);
}
/**
public function buildQuickForm() {
//Setting Upload File Size
$config = CRM_Core_Config::singleton();
- if ($config->maxImportFileSize >= 8388608) {
+
+ $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize.'m');
+ if ($uploadFileSize >= 8388608) {
$uploadFileSize = 8388608;
}
- else {
- $uploadFileSize = $config->maxImportFileSize;
- }
$uploadSize = round(($uploadFileSize / (1024 * 1024)), 2);
$this->assign('uploadSize', $uploadSize);
- $this->add('file', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
-
- $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
- $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize);
+ $this->add('File', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
$this->setMaxFileSize($uploadFileSize);
+ $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize);
+ $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
$this->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File');
$this->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers'));