本文整理汇总了PHP中toBytes函数的典型用法代码示例。如果您正苦于以下问题:PHP toBytes函数的具体用法?PHP toBytes怎么用?PHP toBytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了toBytes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: query
function query($soqlQuery, $queryAction, $queryLocator = null, $suppressScreenOutput = false)
{
if (!WorkbenchConfig::get()->value("allowParentRelationshipQueries") && preg_match("/SELECT.*?(\\w+\\.\\w+).*FROM/i", $soqlQuery, $matches)) {
$msg = "Parent relationship queries are disabled in Workbench: " . $matches[1];
if (WorkbenchConfig::get()->overrideable("allowParentRelationshipQueries")) {
$msg .= "\n\nDue to issues rendering query results, parent relationship queries are disabled by default. " . "If you understand these limitations, parent relationship queries can be enabled under Settings. " . "Alternatively, parent relationship queries can be run with REST Explorer under the Utilities menu without issue.";
}
throw new WorkbenchHandledException($msg);
}
try {
if ($queryAction == 'Query') {
$queryResponse = WorkbenchContext::get()->getPartnerConnection()->query($soqlQuery);
}
if ($queryAction == 'QueryAll') {
$queryResponse = WorkbenchContext::get()->getPartnerConnection()->queryAll($soqlQuery);
}
} catch (SoapFault $e) {
foreach (array("MALFORMED_QUERY", "INVALID_FIELD", "INVALID_TYPE", "INVALID_QUERY_FILTER_OPERATOR", "QUERY_TIMEOUT", "EXCEEDED_ID_LIMIT") as $known) {
if (strpos($e->getMessage(), $known) > -1) {
throw new WorkbenchHandledException($e->getMessage(), 0, $e);
}
}
throw $e;
}
if ($queryAction == 'QueryMore' && isset($queryLocator)) {
$queryResponse = WorkbenchContext::get()->getPartnerConnection()->queryMore($queryLocator);
}
if (stripos($soqlQuery, "count()") && $suppressScreenOutput == false) {
return $queryResponse->size;
} else {
if (!isset($queryResponse->records)) {
return null;
}
}
$records = $queryResponse->records;
$this->totalQuerySize = $queryResponse->size;
if (!$queryResponse->done) {
$this->nextQueryLocator = $queryResponse->queryLocator;
}
//correction for documents and attachments with body. issue #176
if ($queryResponse->size > 0 && !is_array($records)) {
$records = array($records);
}
$memLimitBytes = toBytes(ini_get("memory_limit"));
$memWarningThreshold = WorkbenchConfig::get()->value("memoryUsageWarningThreshold") / 100;
while (($suppressScreenOutput || WorkbenchConfig::get()->value("autoRunQueryMore")) && !$queryResponse->done) {
if ($memLimitBytes != 0 && memory_get_usage() / $memLimitBytes > $memWarningThreshold) {
displayError("Workbench almost exhausted all its memory after only processing " . count($records) . " rows of data.\n When performing a large queries, it is recommended to export as Bulk CSV or Bulk XML.", $suppressScreenOutput, true);
return;
// bail out
}
$queryResponse = WorkbenchContext::get()->getPartnerConnection()->queryMore($queryResponse->queryLocator);
if (!is_array($queryResponse->records)) {
$queryResponse->records = array($queryResponse->records);
}
$records = array_merge($records, $queryResponse->records);
//todo: do memory check here
}
return $records;
}
示例2: init
public function init()
{
$fileMaxSize['postSize'] = toBytes(ini_get('post_max_size'));
$fileMaxSize['uploadSize'] = toBytes(ini_get('upload_max_filesize'));
$this->fileMaxSize = min($fileMaxSize);
parent::init();
}
示例3: init
public function init()
{
$fileMaxSize['postSize'] = toBytes(ini_get('post_max_size'));
$fileMaxSize['uploadSize'] = toBytes(ini_get('upload_max_filesize'));
$this->maxImageSize = min($fileMaxSize);
$this->maxImageSizeMb = round($this->maxImageSize / (1024 * 1024));
parent::init();
}
示例4: init
public function init()
{
$this->preparePaths();
$this->publishAssets();
$fileMaxSize['postSize'] = toBytes(ini_get('post_max_size'));
$fileMaxSize['uploadSize'] = toBytes(ini_get('upload_max_filesize'));
$this->fileMaxSize = min($fileMaxSize);
$this->fileMaxSizeMessage = self::formatBytes($this->fileMaxSize);
parent::init();
}
示例5: getMaxUploadSize
/**
* get the maximum upload size as defined by php ini
* @since 3.4
* @return int max bytes
*/
function getMaxUploadSize()
{
$max_upload = toBytes(ini_get('upload_max_filesize'));
$max_post = toBytes(ini_get('post_max_size'));
$memory_limit = toBytes(ini_get('memory_limit'));
$upload_mb = min($max_upload, $max_post, $memory_limit);
return $upload_mb;
}
示例6: convertCsvFileToArray
/**
* Read a CSV file and return a PHP array
*
* @param csv $file
* @return PHP array
*/
function convertCsvFileToArray($file)
{
ini_set("auto_detect_line_endings", true);
//detect mac os line endings too
$csvArray = array();
$handle = fopen($file, "r");
$memLimitBytes = toBytes(ini_get("memory_limit"));
$memWarningThreshold = WorkbenchConfig::get()->value("memoryUsageWarningThreshold") / 100;
$headerCount = 0;
for ($row = 0; ($data = fgetcsv($handle)) !== FALSE; $row++) {
if ($memLimitBytes != 0 && memory_get_usage() / $memLimitBytes > $memWarningThreshold) {
displayError("Workbench almost exhausted all its memory after only processing {$row} rows of data.\n When performing a large data load, it is recommended to use a zipped request for processing with the Bulk API.\n To do so, rename your CSV file to 'request.txt', zip it, and try uploading again to Workbench.", false, true);
fclose($handle);
return;
}
if ($row == 0) {
$headerCount = count($data);
} else {
$colCount = count($data);
if ($headerCount != $colCount) {
fclose($handle);
throw new WorkbenchHandledException("Invalid CSV file. All rows must have same number of columns.\n" . "Header contains " . amt($headerCount, "column") . ", but data row {$row} contains " . amt($colCount, "column") . ".");
}
}
for ($col = 0; $col < count($data); $col++) {
$csvArray[$row][$col] = $data[$col];
}
}
fclose($handle);
if ($csvArray !== NULL) {
return $csvArray;
} else {
displayError("There were errors parsing the CSV file. Please try again.", false, true);
}
}
示例7: getUploadedFile
function getUploadedFile($FieldName, $MaxSize = 0, $FileTypes = 'csv|txt', $NoRename = false, $dir = '')
{
$currDir = dirname(__FILE__);
if (is_array($_FILES)) {
$f = $_FILES[$FieldName];
} else {
return 'Your php settings don\'t allow file uploads.';
}
if (!$MaxSize) {
$MaxSize = toBytes(ini_get('upload_max_filesize'));
}
if (!is_dir("{$currDir}/csv")) {
@mkdir("{$currDir}/csv");
}
$dir = is_dir($dir) && is_writable($dir) ? $dir : "{$currDir}/csv/";
if ($f['error'] != 4 && $f['name'] != '') {
if ($f['size'] > $MaxSize || $f['error']) {
return 'File size exceeds maximum allowed of ' . intval($MaxSize / 1024) . 'KB';
}
if (!preg_match('/\\.(' . $FileTypes . ')$/i', $f['name'], $ft)) {
return 'File type not allowed. Only these file types are allowed: ' . str_replace('|', ', ', $FileTypes);
}
if ($NoRename) {
$n = str_replace(' ', '_', $f['name']);
} else {
$n = microtime();
$n = str_replace(' ', '_', $n);
$n = str_replace('0.', '', $n);
$n .= $ft[0];
}
if (!@move_uploaded_file($f['tmp_name'], $dir . $n)) {
return 'Couldn\'t save the uploaded file. Try chmoding the upload folder "' . $dir . '" to 777.';
} else {
@chmod($dir . $n, 0666);
return $dir . $n;
}
}
return 'An error occured while uploading the file. Please try again.';
}
示例8: getPathToStaticResource
</div>
</body>
<script type="text/javascript" src="<?php
echo getPathToStaticResource('/script/wz_tooltip.js');
?>
"></script>
<?php
if (isset($_REQUEST["footerScripts"])) {
foreach ($_REQUEST["footerScripts"] as $script) {
print $script . "\n";
}
}
?>
</html>
<?php
$peak = memory_get_peak_usage();
workbenchLog(LOG_INFO, "MemoryUsageCheck", array("measure.memory.peak" => $peak . "byte"));
if (WorkbenchContext::isEstablished() && $peak / toBytes(ini_get("memory_limit")) > 0.7) {
WorkbenchContext::get()->clearCache();
workbenchLog(LOG_INFO, "MemoryUsageCacheClear", array("measure.memory.cache_clear" => 1));
}
if (isset($GLOBALS['REDIS'])) {
redis()->close();
}
//USAGE: debug($showSuperVars = true, $showSoap = true, $customName = null, $customValue = null)
debug(true, true, null, null);
示例9: getSizeLimit
public function getSizeLimit()
{
$min = min(toBytes(ini_get('post_max_size')), toBytes(ini_get('upload_max_filesize')));
return min($min, param('maxImgFileSize', 8 * 1024 * 1024));
}
示例10: defined
<div id="uploadify"></div>
<?php
// create Uploadify uploader
$debug = defined('GSDEBUG') && GSDEBUG == 1 ? 'true' : 'false';
$fileSizeLimit = toBytes(ini_get('upload_max_filesize')) / 1024;
echo "\r\n\t<script type=\"text/javascript\">\r\n\tjQuery(document).ready(function() {\r\n\t\tif(jQuery().uploadify) {\r\n\t\t\$('#uploadify').uploadify({\r\n\t\t\t'debug'\t\t\t: " . $debug . ",\r\n\t\t\t'buttonText'\t: '" . i18n_r('UPLOADIFY_BUTTON') . "',\r\n\t\t\t'buttonCursor'\t: 'pointer',\r\n\t\t\t'uploader'\t\t: 'upload-uploadify.php',\r\n\t\t\t'swf'\t\t\t: 'template/js/uploadify/uploadify.swf',\r\n\t\t\t'multi'\t\t\t: true,\r\n\t\t\t'auto'\t\t\t: true,\r\n\t\t\t'height'\t\t: '25',\r\n\t\t\t'width'\t\t\t: '100%',\r\n\t\t\t'requeueErrors'\t: false,\r\n\t\t\t'fileSizeLimit'\t: '" . $fileSizeLimit . "', // expects input in kb\r\n\t\t\t'cancelImage'\t: 'template/images/cancel.png',\r\n\t\t\t'checkExisting'\t: 'uploadify-check-exists.php?path=" . $path . "',\r\n\t\t\t'postData'\t\t: {\r\n\t\t\t\t'sessionHash' : '" . $SESSIONHASH . "',\r\n\t\t\t\t'path' : '" . $path . "'\r\n\t\t\t},\r\n\t\t\tonUploadProgress: function() {\r\n\t\t\t\t\$('#loader').show();\r\n\t\t\t},\r\n\t\t\tonUploadComplete: function() {\r\n\t\t\t\t\$('#loader').fadeOut(500);\r\n\t\t\t\t\$('#maincontent').load(location.href+' #maincontent', function() {\r\n\t\t\t\t\tattachFilterChangeEvent();\r\n\t\t\t\t});\r\n\t\t\t},\r\n\t\t\tonSelectError: function(file,errorCode,errorMsg) {\r\n\t\t\t\t//alert(file + ' Error ' + errorCode +':'+errorMsg);\r\n\t\t\t},\r\n\t\t\tonUploadError: function(file,errorCode,errorMsg, errorString) {\r\n\t\t\t\talert(errorMsg);\r\n\t\t\t}\r\n\t\t});\r\n\t\t}\r\n\t});\r\n\t</script>";
?>
</li>
<?php
}
?>
<li style="float:right;" id="sb_filesize" ><small><?php
i18n('MAX_FILE_SIZE');
?>
: <strong><?php
echo toBytes(ini_get('upload_max_filesize')) / 1024 / 1024;
?>
MB</strong></small></li>
</ul>
<?php
# show normal upload form if Uploadify is turned off
if (defined('GSNOUPLOADIFY')) {
?>
<form class="uploadform" action="upload.php?path=<?php
echo $path;
?>
" method="post" enctype="multipart/form-data">
<p><input type="file" name="file[]" id="file" style="width:220px;" multiple /></p>
<input type="hidden" name="hash" id="hash" value="<?php
示例11: trim
{
$val = trim($str);
$last = strtolower($str[strlen($str) - 1]);
switch ($last) {
case 'g':
$val *= 1024;
case 'm':
$val *= 1024;
case 'k':
$val *= 1024;
}
return $val;
}
// create Uploadify uploader
$debug = GSDEBUG == 1 ? 'true' : 'false';
$fileSizeLimit = toBytes(ini_get('upload_max_filesize')) / 1024;
echo "\r\n\t<script type=\"text/javascript\">\r\n\tjQuery(document).ready(function() {\r\n\t\tif(jQuery().uploadify) {\r\n\t\t\$('#uploadify').uploadify({\r\n\t\t\t'debug'\t\t\t: " . $debug . ",\r\n\t\t\t'buttonText'\t: '" . i18n_r('UPLOADIFY_BUTTON') . "',\r\n\t\t\t'buttonCursor'\t: 'pointer',\r\n\t\t\t'uploader'\t\t: 'upload-uploadify.php',\r\n\t\t\t'swf'\t\t\t: 'template/js/uploadify/uploadify.swf',\r\n\t\t\t'multi'\t\t\t: true,\r\n\t\t\t'auto'\t\t\t: true,\r\n\t\t\t'height'\t\t: '25',\r\n\t\t\t'width'\t\t\t: '100%',\r\n\t\t\t'requeueErrors'\t: false,\r\n\t\t\t'fileSizeLimit'\t: '" . $fileSizeLimit . "', // expects input in kb\r\n\t\t\t'cancelImage'\t: 'template/images/cancel.png',\r\n\t\t\t'checkExisting'\t: 'uploadify-check-exists.php?path=" . $path . "',\r\n\t\t\t'postData'\t\t: {\r\n\t\t\t\t'sessionHash' : '" . $SESSIONHASH . "',\r\n\t\t\t\t'path' : '" . $path . "'\r\n\t\t\t},\r\n\t\t\tonUploadProgress: function() {\r\n\t\t\t\t\$('#loader').show();\r\n\t\t\t},\r\n\t\t\tonUploadComplete: function() {\r\n\t\t\t\t\$('#loader').fadeOut(500);\r\n\t\t\t\t\$('#maincontent').load(location.href+' #maincontent', function() {\r\n\t\t\t\t\tattachFilterChangeEvent();\r\n\t\t\t\t});\r\n\t\t\t},\r\n\t\t\tonSelectError: function(file,errorCode,errorMsg) {\r\n\t\t\t\t//alert(file + ' Error ' + errorCode +':'+errorMsg);\r\n\t\t\t},\r\n\t\t\tonUploadError: function(file,errorCode,errorMsg, errorString) {\r\n\t\t\t\talert(errorMsg);\r\n\t\t\t}\r\n\t\t});\r\n\t\t}\r\n\t});\r\n\t</script>";
?>
</li>
<?php
}
?>
<li style="float:right;"><small><?php
i18n('MAX_FILE_SIZE');
?>
: <strong><?php
echo ini_get('upload_max_filesize');
?>
B</strong></small></li>
</ul>
示例12: formatBytes
function formatBytes($bytes, $precision = 2)
{
$units = array('', 'k', 'M', 'G', 'T');
$bytes = max(toBytes($bytes), 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= pow(1024, $pow);
return round($bytes, $precision) . $units[$pow];
}
示例13: dirname
// Upload process
require_once dirname(__FILE__) . "/qqUploadedFileXhr.class.php";
if (isset($_GET['qqfile'])) {
$file = new qqUploadedFileXhr();
} elseif (isset($_FILES['qqfile'])) {
$file = new qqUploadedFileForm();
} else {
$file = false;
}
$pathinfo = pathinfo(strtolower($file->getName()));
$filename = JApplication::stringURLSafe($pathinfo['filename']);
$ext = $pathinfo['extension'];
// Max size to upload (10MB)
$sizeLimit = 10 * 1024 * 1024;
$postSize = toBytes(ini_get('post_max_size'));
$uploadSize = toBytes(ini_get('upload_max_filesize'));
// allowed extensions to upload
$allowedExtensions = array('jpg', 'jpeg', 'png', 'gif');
$response = array('success' => false, 'message' => '');
$moduleID = JRequest::getInt('id', 0);
$dir = JPATH_BASE . '/images';
$user = JFactory::getUser();
if ($user->guest) {
$response['message'] = "This function only for logged users!";
} else {
if (!$file) {
$response['message'] = "No files are found!";
} else {
if ($file->getSize() == 0) {
$response['message'] = "File is empty, check your file and try again";
} else {
示例14: get_memory_limit
function get_memory_limit()
{
if (!function_exists('ini_get')) {
return -1;
}
return toBytes(ini_get('memory_limit'));
}
示例15: getPathToStaticResource
}
print "Workbench " . ($GLOBALS["WORKBENCH_VERSION"] != "trunk" ? $GLOBALS["WORKBENCH_VERSION"] : "") . "<br/>\n";
?>
</div>
</body>
<script type="text/javascript" src="<?php
echo getPathToStaticResource('/script/wz_tooltip.js');
?>
"></script>
<?php
if (isset($_REQUEST["footerScripts"])) {
foreach ($_REQUEST["footerScripts"] as $script) {
print $script . "\n";
}
}
?>
</html>
<?php
if (WorkbenchContext::isEstablished() && memory_get_peak_usage() / toBytes(ini_get("memory_limit")) > 0.7) {
WorkbenchContext::get()->clearCache();
}
if (isset($GLOBALS['REDIS'])) {
redis()->close();
}
//USAGE: debug($showSuperVars = true, $showSoap = true, $customName = null, $customValue = null)
debug(true, true, null, null);