123456 $val = substr($val, 0, $sigFigs); // ex: 123456 => 1234 // Move any extra digits after decimal $extraFigs = strlen($val) - ($sigFigs - $decFigs); if ($extraFigs > 0) { return $sign * $val / pow(10, $extraFigs); // ex: 1234 => 1.234 } else { return $sign * $val; } } /** * Some kind of numbery-looky-printy thing. * * @param string $size * @param bool $checkForPostMax * * @return int */ public static function formatUnitSize($size, $checkForPostMax = FALSE) { if ($size) { $last = strtolower($size{strlen($size) - 1}); $size = (int) $size; 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) Administrator >> System Settings >> Misc. 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; } } }