Merge pull request #3585 from atif-shaikh/CRM-14199
[civicrm-core.git] / CRM / Core / Config / Defaults.php
index 3b7e5e65476f4d4855ed8483790cbb7f46b6ceec..b942b907a673c20fa85d993e35f61ec97aaaae4a 100644 (file)
@@ -69,6 +69,19 @@ class CRM_Core_Config_Defaults {
     $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) {
@@ -81,15 +94,22 @@ class CRM_Core_Config_Defaults {
         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;
     }
   }
 
   /**
    * Function to set the default values
    *
-   * @param array   $defaults  associated array of form elements
-   * @param boolena $formMode  this funtion is called to set default
+   * @param array $defaults associated array of form elements
+   * @param bool|\boolena $formMode this funtion is called to set default
    *                           values in an empty db, also called when setting component using GUI
    *                           this variable is set true for GUI
    *                           mode (eg: Global setting >> Components)