本文整理汇总了PHP中utils::ConvertToBytes方法的典型用法代码示例。如果您正苦于以下问题:PHP utils::ConvertToBytes方法的具体用法?PHP utils::ConvertToBytes怎么用?PHP utils::ConvertToBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils
的用法示例。
在下文中一共展示了utils::ConvertToBytes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GetMaxUpload
protected function GetMaxUpload()
{
$iMaxUpload = ini_get('upload_max_filesize');
if (!$iMaxUpload) {
$sRet = Dict::S('Attachments:UploadNotAllowedOnThisSystem');
} else {
$iMaxUpload = utils::ConvertToBytes($iMaxUpload);
if ($iMaxUpload > 1024 * 1024 * 1024) {
$sRet = Dict::Format('Attachment:Max_Go', sprintf('%0.2f', $iMaxUpload / (1024 * 1024 * 1024)));
} else {
if ($iMaxUpload > 1024 * 1024) {
$sRet = Dict::Format('Attachment:Max_Mo', sprintf('%0.2f', $iMaxUpload / (1024 * 1024)));
} else {
$sRet = Dict::Format('Attachment:Max_Ko', sprintf('%0.2f', $iMaxUpload / 1024));
}
}
}
return $sRet;
}
示例2: SetMemoryLimit
function SetMemoryLimit($oP)
{
$sMemoryLimit = trim(ini_get('memory_limit'));
if (empty($sMemoryLimit)) {
// On some PHP installations, memory_limit does not exist as a PHP setting!
// (encountered on a 5.2.0 under Windows)
// In that case, ini_set will not work, let's keep track of this and proceed with the data load
$oP->p("No memory limit has been defined in this instance of PHP");
} else {
// Check that the limit will allow us to load the data
//
$iMemoryLimit = utils::ConvertToBytes($sMemoryLimit);
if ($iMemoryLimit < SAFE_MINIMUM_MEMORY) {
if (ini_set('memory_limit', SAFE_MINIMUM_MEMORY) === FALSE) {
$oP->p("memory_limit is too small: {$iMemoryLimit} and can not be increased by the script itself.");
} else {
$oP->p("memory_limit increased from {$iMemoryLimit} to " . SAFE_MINIMUM_MEMORY . ".");
}
}
}
}
示例3: GetFormElementForField
//.........这里部分代码省略.........
$sEditValue = $oAttDef->GetEditValue($value);
$sPreviousLog = is_object($value) ? $value->GetAsHTML($oPage, true, array('AttributeText', 'RenderWikiHtml')) : '';
$iEntriesCount = is_object($value) ? count($value->GetIndex()) : 0;
$sHidden = "<input type=\"hidden\" id=\"{$iId}_count\" value=\"{$iEntriesCount}\"/>";
// To know how many entries the case log already contains
$sHTMLValue = "<div class=\"caselog\" {$sStyle}><table style=\"width:100%;\"><tr><td>{$sHeader}<textarea style=\"border:0;width:100%\" title=\"{$sHelpText}\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" rows=\"8\" cols=\"40\" id=\"{$iId}\">" . htmlentities($sEditValue, ENT_QUOTES, 'UTF-8') . "</textarea>{$sPreviousLog}</td><td>{$sValidationField}</td></tr></table>{$sHidden}</div>";
$oPage->add_ready_script("\$('#{$iId}').bind('keyup change validate', function(evt, sFormId) { return ValidateCaseLogField('{$iId}', {$bMandatory}, sFormId) } );");
// Custom validation function
break;
case 'HTML':
$oWidget = new UIHTMLEditorWidget($iId, $oAttDef, $sNameSuffix, $sFieldPrefix, $sHelpText, $sValidationField, $value, $bMandatory);
$sHTMLValue = $oWidget->Display($oPage, $aArgs);
break;
case 'LinkedSet':
if ($oAttDef->IsIndirect()) {
$oWidget = new UILinksWidget($sClass, $sAttCode, $iId, $sNameSuffix, $oAttDef->DuplicatesAllowed(), $aArgs);
} else {
$oWidget = new UILinksWidgetDirect($sClass, $sAttCode, $iId, $sNameSuffix, $aArgs);
}
$aEventsList[] = 'validate';
$aEventsList[] = 'change';
$oObj = isset($aArgs['this']) ? $aArgs['this'] : null;
$sHTMLValue = $oWidget->Display($oPage, $value, array(), $sFormPrefix, $oObj);
break;
case 'Document':
$aEventsList[] = 'validate';
$aEventsList[] = 'change';
$oDocument = $value;
// Value is an ormDocument object
$sFileName = '';
if (is_object($oDocument)) {
$sFileName = $oDocument->GetFileName();
}
$iMaxFileSize = utils::ConvertToBytes(ini_get('upload_max_filesize'));
$sHTMLValue = "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"{$iMaxFileSize}\" />\n";
$sHTMLValue .= "<input name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}[filename]\" type=\"hidden\" id=\"{$iId}\" \" value=\"" . htmlentities($sFileName, ENT_QUOTES, 'UTF-8') . "\"/>\n";
$sHTMLValue .= "<span id=\"name_{$iInputId}\">{$sFileName}</span><br/>\n";
$sHTMLValue .= "<input title=\"{$sHelpText}\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}[fcontents]\" type=\"file\" id=\"file_{$iId}\" onChange=\"UpdateFileName('{$iId}', this.value)\"/> {$sValidationField}\n";
break;
case 'StopWatch':
$sHTMLValue = "The edition of a stopwatch is not allowed!!!";
break;
case 'List':
// Not editable for now...
$sHTMLValue = '';
break;
case 'One Way Password':
$aEventsList[] = 'validate';
$oWidget = new UIPasswordWidget($sAttCode, $iId, $sNameSuffix);
$sHTMLValue = $oWidget->Display($oPage, $aArgs);
// Event list & validation is handled directly by the widget
break;
case 'ExtKey':
$aEventsList[] = 'validate';
$aEventsList[] = 'change';
$oAllowedValues = MetaModel::GetAllowedValuesAsObjectSet($sClass, $sAttCode, $aArgs);
$sFieldName = $sFieldPrefix . $sAttCode . $sNameSuffix;
$aExtKeyParams = $aArgs;
$aExtKeyParams['iFieldSize'] = $oAttDef->GetMaxSize();
$aExtKeyParams['iMinChars'] = $oAttDef->GetMinAutoCompleteChars();
$sHTMLValue = UIExtKeyWidget::DisplayFromAttCode($oPage, $sAttCode, $sClass, $oAttDef->GetLabel(), $oAllowedValues, $value, $iId, $bMandatory, $sFieldName, $sFormPrefix, $aExtKeyParams);
$sHTMLValue .= "<!-- iFlags: {$iFlags} bMandatory: {$bMandatory} -->\n";
break;
case 'RedundancySetting':
$sHTMLValue = '<table>';
$sHTMLValue .= '<tr>';
示例4: CheckServerConnection
/**
* Helper function check the connection to the database, verify a few conditions (minimum version, etc...) and (if connected)
* enumerate the existing databases (if possible)
* @return mixed false if the connection failed or array('checks' => Array of CheckResult, 'databases' => Array of database names (as strings) or null if not allowed)
*/
static function CheckServerConnection($sDBServer, $sDBUser, $sDBPwd)
{
$aResult = array('checks' => array(), 'databases' => null);
try {
$oDBSource = new CMDBSource();
$oDBSource->Init($sDBServer, $sDBUser, $sDBPwd);
$aResult['checks'][] = new CheckResult(CheckResult::INFO, "Connection to '{$sDBServer}' as '{$sDBUser}' successful.");
$aResult['checks'][] = new CheckResult(CheckResult::INFO, "Info - User privileges: " . $oDBSource->GetRawPrivileges());
$sDBVersion = $oDBSource->GetDBVersion();
if (version_compare($sDBVersion, self::MYSQL_MIN_VERSION, '>=')) {
$aResult['checks'][] = new CheckResult(CheckResult::INFO, "Current MySQL version ({$sDBVersion}), greater than minimum required version (" . self::MYSQL_MIN_VERSION . ")");
// Check some server variables
$iMaxAllowedPacket = $oDBSource->GetServerVariable('max_allowed_packet');
$iMaxUploadSize = utils::ConvertToBytes(ini_get('upload_max_filesize'));
if ($iMaxAllowedPacket >= 500 + $iMaxUploadSize) {
$aResult['checks'][] = new CheckResult(CheckResult::INFO, "MySQL server's max_allowed_packet ({$iMaxAllowedPacket}) is big enough compared to upload_max_filesize ({$iMaxUploadSize}).");
} else {
if ($iMaxAllowedPacket < $iMaxUploadSize) {
$aResult['checks'][] = new CheckResult(CheckResult::WARNING, "MySQL server's max_allowed_packet ({$iMaxAllowedPacket}) is not big enough. Please, consider setting it to at least " . (500 + $iMaxUploadSize) . ".");
}
}
$iMaxConnections = $oDBSource->GetServerVariable('max_connections');
if ($iMaxConnections < 5) {
$aResult['checks'][] = new CheckResult(CheckResult::WARNING, "MySQL server's max_connections ({$iMaxConnections}) is not enough. Please, consider setting it to at least 5.");
} else {
$aResult['checks'][] = new CheckResult(CheckResult::INFO, "MySQL server's max_connections is set to {$iMaxConnections}.");
}
} else {
$aResult['checks'][] = new CheckResult(CheckResult::ERROR, "Error: Current MySQL version is ({$sDBVersion}), minimum required version (" . self::MYSQL_MIN_VERSION . ")");
}
try {
$aResult['databases'] = $oDBSource->ListDB();
} catch (Exception $e) {
$aResult['databases'] = null;
}
} catch (Exception $e) {
return false;
}
return $aResult;
}
示例5: define
*/
define('SAFE_MINIMUM_MEMORY', 64 * 1024 * 1024);
require_once '../approot.inc.php';
require_once APPROOT . '/application/utils.inc.php';
require_once APPROOT . '/setup/setuppage.class.inc.php';
require_once APPROOT . '/setup/moduleinstaller.class.inc.php';
$sMemoryLimit = trim(ini_get('memory_limit'));
if (empty($sMemoryLimit)) {
// On some PHP installations, memory_limit does not exist as a PHP setting!
// (encountered on a 5.2.0 under Windows)
// In that case, ini_set will not work, let's keep track of this and proceed with the data load
SetupPage::log_info("No memory limit has been defined in this instance of PHP");
} else {
// Check that the limit will allow us to load the data
//
$iMemoryLimit = utils::ConvertToBytes($sMemoryLimit);
if ($iMemoryLimit < SAFE_MINIMUM_MEMORY) {
if (ini_set('memory_limit', SAFE_MINIMUM_MEMORY) === FALSE) {
SetupPage::log_error("memory_limit is too small: {$iMemoryLimit} and can not be increased by the script itself.");
} else {
SetupPage::log_info("memory_limit increased from {$iMemoryLimit} to " . SAFE_MINIMUM_MEMORY . ".");
}
}
}
function FatalErrorCatcher($sOutput)
{
if (preg_match('|<phpfatalerror>.*</phpfatalerror>|s', $sOutput, $aMatches)) {
header("HTTP/1.0 500 Internal server error.");
$errors = '';
foreach ($aMatches as $sMatch) {
$errors .= strip_tags($sMatch) . "\n";