本文整理汇总了PHP中format_bytes函数的典型用法代码示例。如果您正苦于以下问题:PHP format_bytes函数的具体用法?PHP format_bytes怎么用?PHP format_bytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了format_bytes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: print_states
function print_states($tracker)
{
global $rulescnt;
$rulesid = "";
$bytes = 0;
$states = 0;
$packets = 0;
$evaluations = 0;
$stcreations = 0;
$rules = get_pf_rules($rulescnt, $tracker);
if (is_array($rules)) {
foreach ($rules as $rule) {
$bytes += $rule['bytes'];
$states += $rule['states'];
$packets += $rule['packets'];
$evaluations += $rule['evaluations'];
$stcreations += $rule['state creations'];
if (strlen($rulesid) > 0) {
$rulesid .= ",";
}
$rulesid .= "{$rule['id']}";
}
}
printf("<a href=\"diag_dump_states.php?ruleid=%s\" data-toggle=\"popover\" data-trigger=\"hover focus\" title=\"%s\" ", $rulesid, gettext("States details"));
printf("data-content=\"evaluations: %s<br>packets: %s<br>bytes: %s<br>states: %s<br>state creations: %s\" data-html=\"true\">", format_number($evaluations), format_number($packets), format_bytes($bytes), format_number($states), format_number($stcreations));
printf("%d/%s</a><br>", format_number($states), format_bytes($bytes));
}
示例2: artc
public function artc()
{
$id = I('id');
$info = D('Article')->get_info($id);
if (!$info) {
$this->error('非法ID!', U('Index/index'), false, true);
}
$info['description'] = stripcslashes($info['description']);
preg_match_all("/(?<=\\[attach\\])([\\d]*)(?=\\[\\/attach\\])/", $info['description'], $arr);
preg_match_all("/(?<=\\[qnattach\\])([\\d]*)(?=\\[\\/qnattach\\])/", $info['description'], $qnarr);
foreach ($arr[0] as $key => $vo) {
$replace = '<a href="' . U('File/download', array('id' => think_encrypt($vo))) . '" target="_blank" >' . getattachname($vo) . '</a><span class="attachspan">(下载次数:' . getattachdnum($vo) . '次;大小:' . format_bytes(getattachsize($vo)) . ')</span>';
$info['description'] = str_replace('[attach]' . $vo . '[/attach]', $replace, $info['description']);
}
foreach ($qnarr[0] as $key1 => $vo1) {
$replace1 = '<a href="' . U('File/download', array('qn' => 1, 'id' => think_encrypt($vo1))) . '" target="_blank" >' . getqnattachname($vo1) . '</a><span class="attachspan">(下载次数:' . getqnattachdnum($vo1) . '次;大小:' . format_bytes(getqnattachsize($vo1)) . ')</span>';
$info['description'] = str_replace('[qnattach]' . $vo1 . '[/qnattach]', $replace1, $info['description']);
}
if ($info['status'] != 1 && $info['uid'] != $_SESSION['cs_home']['user_auth']['uid']) {
$this->error('你无权查看该内容!', '', false, true);
}
$focus['rowid'] = $info['id'];
$focus['type'] = 1;
if ($sccount = M('focus')->where($focus)->count() != $info['sccount']) {
D('Article')->where(array('id' => $id))->setField('sccount', $sccount);
}
D('Article')->where(array('id' => $id))->setInc('view', 1);
if (!empty($info['tag'])) {
$tags = explode(',', $info['tag']);
$info['linktag'] = '';
foreach ($tags as $key1 => $vo1) {
$maptag['title'] = $vo1;
$maptag['type'] = 1;
$tagid = M('tags')->where($maptag)->getField('id');
$url = CSU('/tagart/' . $tagid, 'Index/tagart', array('id' => $tagid));
$info['linktag'] .= '<a style="margin-left:5px;" href="' . $url . '">[' . $vo1 . ']</a>';
$info['tagarr'][$key1] = '<a class="tag" href="' . $url . '">' . $vo1 . '</a>';
}
}
$shareurl = 'http://' . $_SERVER['HTTP_HOST'] . CSU('/artc/' . $info['id'], 'Index/artc', array('id' => $info['id']));
$sharedes = '原文链接:' . $shareurl;
$sharetitle = $info['title'] . '-' . C('WEB_SITE_TITLE');
$authorinfo = query_user(array('space_url', 'signature', 'avatar64', 'nickname'), $info['uid']);
$map['id'] = is_login();
$map['rowid'] = $info['id'];
$map['type'] = 1;
if (M('Focus')->where($map)->count() > 0) {
$hassc = true;
}
$this->assign('shareurl', $shareurl);
$this->assign('hassc', $hassc);
$this->assign('sharedes', $sharedes);
$this->assign('sharetitle', $sharetitle);
$this->assign('authorinfo', $authorinfo);
$this->assign('info', $info);
$this->assign('webdescription', $info['title']);
$this->assign('webkeyword', $info['title']);
$this->assign('webtitle', $info['title']);
$this->display();
}
示例3: Movie_thumbnail
function Movie_thumbnail($filelist, $gallery, $dirkey, $filekey, $basedir)
{
$filename = $filelist[$filekey];
$file = "{$basedir}/{$filename}";
$mimetype = mime_content_type($file);
$filesize = filesize($file);
$nicefilesize = format_bytes($filesize);
$caption = get_caption($file);
if (!isset($caption) || $caption == "") {
$caption = $filename;
}
$imagetag = " MOVIE: {$filename} <br/>";
$filesize_display = " File Size: {$nicefilesize} <br/>";
#<a href='?action=send_file&gallery=$gallery&dirkey=$dirkey&filekey=$filekey'>
print <<<HTMLEND
<div class=thumbnail >
\t\t<div class=movie >
\t\t{$imagetag}
\t\t{$filesize_display}
\t\t<a href='send_file.php?mode=attach&gallery={$gallery}&dirkey={$dirkey}&filekey={$filekey}'>
\t\tDownload
\t\t</a>
\t\t|
\t\t<a href='gallery.php?action=display_image&gallery={$gallery}&dirkey={$dirkey}&filekey={$filekey}' type='{$mimetype}' >
\t\tView in browser
\t\t</a>
\t</div>
</div>
HTMLEND;
}
示例4: scandir_tree
/**
* 扫描目录所有文件,并生成treegrid数据
* @param string $path 目录
* @param string $filter 过滤文件名
* @param number $i 辅助用,这个不用传参
* @return array
*/
function scandir_tree($path, $filter = SITE_DIR, &$i = 1)
{
$result = array();
$path = realpath($path);
$path = str_replace(array('/', '\\'), DS, $path);
$filter = str_replace(array('/', '\\'), DS, $filter);
$list = glob($path . DS . '*');
foreach ($list as $key => $filename) {
$result[$key]['id'] = $i;
$result[$key]['name'] = str_replace($filter, '', $filename);
$i++;
if (is_dir($filename)) {
$result[$key]['type'] = 'dir';
$result[$key]['size'] = '-';
$result[$key]['mtime'] = '-';
$result[$key]['state'] = 'closed';
$result[$key]['children'] = scandir_tree($filename, $filter, $i);
//easyui当children为空时会出现问题,因此在这里过滤
if (empty($result[$key]['children'])) {
$result[$key]['iconCls'] = 'tree-folder';
unset($result[$key]['state']);
unset($result[$key]['children']);
}
} else {
$result[$key]['type'] = 'file';
$result[$key]['size'] = format_bytes(filesize($filename), ' ');
$result[$key]['mtime'] = date('Y-m-d H:i:s', filemtime($filename));
}
}
return $result;
}
示例5: _after_find
protected function _after_find(&$result, $options)
{
$result['update_time_text'] = date('Y-m-d H:i:s', $result['update_time']);
$result['document_title'] = M('Doc0s1')->getFieldById($result['record_id'], 'title');
//$result['document_title'] = M('Document')->getFieldById($result['record_id'], 'title');
$result['size'] = format_bytes($result['size']);
}
示例6: lists
public function lists()
{
$type = I('get.type', 'Picture');
$type = ucfirst($type);
$title = I('get.title');
if (empty($this->_path[$type])) {
$this->error($type . '请选择正确的资源类型');
}
$files_list = array();
//获取该目录下所有文件
$fileslist = Amango_Scanfiles('./Uploads/' . $type . '/');
$files_list = explode(',', $fileslist);
$current_path = $this->_path[$type][1];
//获取路径
if (in_array($title, $files_list)) {
$current_path = $current_path . $title . '/';
$parent_ext = './' . $title . '/';
} else {
$parent_ext = './';
}
$file_list = array();
//遍历目录下文件 取得文件信息
$totalkbs = 0;
if ($handle = opendir($current_path)) {
$i = 0;
while (false !== ($filename = readdir($handle))) {
if ($filename[0] == '.') {
continue;
}
$file = $current_path . $filename;
if (!is_dir($file)) {
$file_ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
if (!in_array($file_ext, $this->deny_ext_arr)) {
$nowsize = filesize($file);
$filesize = $filesize + $nowsize;
$file_list[$parent_ext][$i]['is_dir'] = false;
$file_list[$parent_ext][$i]['has_file'] = false;
$file_list[$parent_ext][$i]['filesize'] = format_bytes($nowsize);
$file_list[$parent_ext][$i]['dir_path'] = '';
$file_list[$parent_ext][$i]['filetype'] = $file_ext;
$file_list[$parent_ext][$i]['filename'] = $filename;
//文件名,包含扩展名
$file_list[$parent_ext][$i]['datetime'] = date('Y-m-d H:i:s', filectime($file));
//文件最后修改时间
}
}
$i++;
}
closedir($handle);
}
$this->assign('filesize', format_bytes($filesize));
$this->assign('filenums', count($file_list[$parent_ext]));
$this->assign('type', $type);
$this->assign('nowdir', $title);
$this->assign('sub_dirs', $files_list);
$this->assign('subfileslist', $file_list[$parent_ext]);
$this->assign('catename', $this->_path[$type][0]);
$this->display();
}
示例7: import_list
/**
* 数据库备份/还原列表
*/
public function import_list($type = null)
{
if (IS_POST) {
$path = C('DATA_BACKUP_PATH');
if (!is_dir($path)) {
mkdir($path, 0755, true);
}
$path = realpath($path);
$flag = \FilesystemIterator::KEY_AS_FILENAME;
$glob = new \FilesystemIterator($path, $flag);
$list = array();
foreach ($glob as $name => $file) {
if (preg_match('/^\\d{8,8}-\\d{6,6}-\\d+\\.sql(?:\\.gz)?$/', $name)) {
$name = sscanf($name, '%4s%2s%2s-%2s%2s%2s-%d');
$date = "{$name[0]}-{$name[1]}-{$name[2]}";
$time = "{$name[3]}:{$name[4]}:{$name[5]}";
$part = $name[6];
if (isset($list["{$date} {$time}"])) {
$info = $list["{$date} {$time}"];
$info['part'] = max($info['part'], $part);
$info['size'] = $info['size'] + $file->getSize();
} else {
$info['part'] = $part;
$info['size'] = $file->getSize();
}
$extension = strtoupper(pathinfo($file->getFilename(), PATHINFO_EXTENSION));
$info['compress'] = $extension === 'SQL' ? '-' : $extension;
$info['time'] = strtotime("{$date} {$time}");
$list["{$date} {$time}"] = $info;
}
}
foreach ($list as $list_key => $list_one) {
$_list_one['id'] = date('Ymd-His', $list_one['time']);
$_list_one['part'] = $list_one['part'];
$_list_one['size'] = format_bytes($list_one['size']);
$_list_one['compress'] = $list_one['compress'];
$_list_one['time'] = $list_key;
$_list_one['operate'] = '
<a href="#" onclick="Ajax_DatabaseImport(\'' . U('import', array('time' => $list_one['time'])) . '\',\'DatabaseImport_Data_List\');">还原</a>
<a href="#" onclick="Datagrid_Ajax(\'' . U('del', array('time' => $list_one['time'])) . '\',\'DatabaseImport_Data_List\');">删除</a>
';
$_list[] = $_list_one;
}
$total = count($_list);
if ($total == 0) {
$_list = '';
}
$data = array('total' => $total, 'rows' => $_list);
$this->ajaxReturn($data);
} else {
$operate = '
<a class="easyui-linkbutton" href="JavaScript:void(0);" data-options="iconCls:\'iconfont icon-refresh\',plain:true" onclick="Data_Reload(\'DatabaseImport_Data_List\');">刷新还原列表</a>
';
$this->assign('operate', $operate);
$this->display();
}
}
示例8: getUsedDiskSpace
/**
* Returns disk space data
*
* @return array
*/
public function getUsedDiskSpace()
{
$disk_space['b_free'] = disk_free_space('/');
$disk_space['b_total'] = disk_total_space('/');
$disk_space['free'] = format_bytes($disk_space['b_free']);
$disk_space['total'] = format_bytes($disk_space['b_total']);
$disk_space['used'] = format_bytes($disk_space['b_total'] - $disk_space['b_free']);
$disk_space['per_used'] = 100 - (int) ($disk_space['b_free'] / $disk_space['b_total'] * 100);
return $disk_space;
}
示例9: step1
public function step1()
{
$items = array(array('os' => array('操作系统', 1, null, PHP_OS), 'php' => array('PHP版本', 0, '5.3', PHP_VERSION), 'upload' => array('附件上传', 1, null, function_exists('ini_get') ? ini_get('upload_max_filesize') : '未知'), 'disk' => array('磁盘空间', 1, null, function_exists('disk_free_space') ? format_bytes(disk_free_space(realpath(SITE_DIR))) : '未知')), array('pdo' => array('pdo', 0, null, '不支持', 'class_exists'), 'pdo_mysql' => array('pdo_mysql', 0, null, '不支持', 'extension_loaded'), 'json' => array('json', 0, null, '不支持', 'extension_loaded'), 'curl_init' => array('curl', 0, null, '不支持', 'function_exists'), 'gd' => array('gd', 0, null, '不支持', 'extension_loaded'), 'Imagick' => array('imagick', 0, null, '建议开启(可选)', 'class_exists'), 'Gmagick' => array('gmagick', 0, null, '建议开启(可选)', 'class_exists')), array(array(str_replace(SITE_DIR, '.', CONF_PATH . 'config.php'), 0, null, '不可写', CONF_PATH . 'config.php'), array(str_replace(SITE_DIR, '.', RUNTIME_PATH), 0, null, '不可写', RUNTIME_PATH), array(UPLOAD_PATH, 0, null, '不可写', UPLOAD_PATH)));
if (APP_MODE == 'sae') {
unset($items[2]);
}
$status = true;
foreach ($items as $k => &$item) {
foreach ($item as $k2 => &$info) {
if ($info[1]) {
continue;
}
switch ($k) {
case 0:
//运行环境
if ($k2 == 'php') {
if ($info[3] >= $info[2]) {
$info[1] = 1;
} else {
$status = false;
}
}
break;
case 1:
//扩展支持
if ($info[4]($k2)) {
$info[1] = 1;
$info[3] = '支持';
} else {
if (in_array($k2, array('Imagick', 'Gmagick'))) {
break;
}
$status = false;
}
break;
case 2:
//权限检测
if (is_writable($info[4])) {
$info[1] = 1;
$info[3] = '可写';
} else {
$status = false;
}
break;
}
}
}
if ($status) {
session('install_step', 2);
}
$this->assign('item', array($status, $items));
$this->display();
}
示例10: filelist_rubbish
public function filelist_rubbish()
{
$File = M('File');
$where['status'] = 0;
$count = $File->where($where)->count();
$Page = new \Think\Page($count, 24);
$show = $Page->show();
$filelist = $File->where($where)->field(true)->order('addtime desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
foreach ($filelist as $key => &$val) {
$val['size'] = format_bytes($val['size']);
}
$this->assign('filelist', $filelist);
$this->assign('pages', $show);
$this->display();
}
示例11: hasErrors
public function hasErrors()
{
// check file size
if ($this->maxFileSize && $_FILES[$this->altName()]['size'] > $this->maxFileSize) {
$this->errors[] = t('The file size exceeds max of ' . format_bytes($this->maxFileSize));
}
// file extensions allowed validator
if ($this->allowedExtensions) {
$extValidator = new \Meta\Validation\FileExtension(array('allowedExtensions' => $this->allowedExtensions, 'value' => $this->getValue()));
if (!$extValidator->execute()) {
$this->errors[] = $extValidator->error();
}
}
return count($this->errors) > 0;
}
示例12: importlist
/**
* 数据库还原列表
*/
public function importlist()
{
if (IS_POST) {
$path = C('DATA_BACKUP_PATH');
if (!is_dir($path)) {
mkdir($path, 0755, true);
}
$path = realpath($path);
$flag = \FilesystemIterator::KEY_AS_FILENAME;
$glob = new \FilesystemIterator($path, $flag);
$list = array();
foreach ($glob as $name => $file) {
if (preg_match('/^\\d{8,8}-\\d{6,6}-\\d+\\.sql(?:\\.gz)?$/', $name)) {
$name = sscanf($name, '%4s%2s%2s-%2s%2s%2s-%d');
$date = "{$name[0]}-{$name[1]}-{$name[2]}";
$time = "{$name[3]}:{$name[4]}:{$name[5]}";
$part = $name[6];
if (isset($list["{$date} {$time}"])) {
$info = $list["{$date} {$time}"];
$info['part'] = max($info['part'], $part);
$info['size'] = $info['size'] + $file->getSize();
} else {
$info['part'] = $part;
$info['size'] = $file->getSize();
}
$extension = strtoupper(pathinfo($file->getFilename(), PATHINFO_EXTENSION));
$info['compress'] = $extension === 'SQL' ? '-' : $extension;
$info['time'] = strtotime("{$date} {$time}");
$list["{$date} {$time}"] = $info;
}
}
$temp = array();
foreach ($list as $key => $value) {
$list[$key]['name'] = date('Ymd-His', strtotime($key));
$list[$key]['datetime'] = date('Y-m-d H:i:s', strtotime($key));
$list[$key]['size'] = format_bytes($list[$key]['size']);
$temp[] = $list[$key];
}
$list = $temp;
$this->ajaxReturn($list);
} else {
$currentpos = D('Menu')->currentPos(I('get.menuid'));
//栏目位置
$treegrid = array('options' => array('title' => $currentpos, 'url' => U('Database/importlist', array('grid' => 'treegrid')), 'idField' => 'time', 'treefield' => 'time'), 'fields' => array('备份名称' => array('field' => 'name', 'width' => 80), '卷数' => array('field' => 'part', 'width' => 50), '压缩' => array('field' => 'compress', 'width' => 50), '数据大小' => array('field' => 'size', 'width' => 50, 'formatter' => 'function(size){return "<font color=green>"+size+"</font>";}'), '备份时间' => array('field' => 'datetime', 'width' => 80, 'formatter' => 'function(datetime){return "<font color=red>"+datetime+"</font>";}'), '管理操作' => array('field' => 'time', 'width' => 80, 'formatter' => 'databaseImportModule.operate')));
$this->assign('treegrid', $treegrid);
$this->display("import");
}
}
示例13: build_folder_structure
/**
* Recursively construct the proper HTML
* for representing a folder full of items
*
* @param array $dirs array of directory objects to process
* @param array $path_array path components in array form
* @param array $item_info metadata about each item
*
* @return void
*
* @author Ken Auberry <kenneth.auberry@pnnl.gov>
*/
function build_folder_structure(&$dirs, $path_array, $item_info)
{
if (count($path_array) > 1) {
if (!isset($dirs['folders'][$path_array[0]])) {
$dirs['folders'][$path_array[0]] = array();
}
build_folder_structure($dirs['folders'][$path_array[0]], array_splice($path_array, 1), $item_info);
} else {
$size_string = format_bytes($item_info['size']);
$item_id = $item_info['item_id'];
$url = base_url() . "myemsl/itemauth/{$item_id}";
$item_info['url'] = $url;
$item_info_json = json_encode($item_info);
$dirs['files'][$item_id] = "<a class='item_link' id='item_{$item_id}' href='#'>{$path_array[0]}</a> <span class='fineprint'>[size: {$size_string}]</span><span class='item_data_json' id='item_id_{$item_id}' style='display:none;'>{$item_info_json}</span>";
}
}
示例14: drive_details
function drive_details($drive)
{
if (isset($drive["fsSize"])) {
$pdsize = $drive["fsSize"] * 1024;
$pfree = $drive["fsFree"] * 1024;
$pused = $pdsize - $pfree;
$pused_size = $pused / $pdsize * 100;
$output['used'] = format_bytes($pused, true, '', '');
$output['free'] = format_bytes($pfree, true, '', '');
$output['percent'] = $pused_size;
}
$output['id'] = $drive["id"] . " (" . $drive["device"] . ")";
$output['temp'] = $drive['temp'];
$output['size'] = format_bytes($drive["size"] * 1024);
$output['errors'] = $drive['numErrors'];
return $output;
}
示例15: file_list_upload
/**
* 上传目录列表
* @param string $path 目录名
* @return array
*/
function file_list_upload($path)
{
$config = C('TMPL_PARSE_STRING');
switch (strtoupper(C('FILE_UPLOAD_TYPE'))) {
case 'SAE':
$path = str_replace(DS, '/', rtrim($path, DS));
$arr = explode('/', ltrim($path, './'));
$domain = array_shift($arr);
$filePath = implode('/', $arr);
$s = new SaeStorage();
$list = $s->getListByPath($domain, $filePath);
$res = array();
while (isset($list['dirNum']) && $list['dirNum']) {
$list['dirNum']--;
array_push($res, array('type' => 'dir', 'name' => $list['dirs'][$list['dirNum']]['name'], 'path' => ltrim($list['dirs'][$list['dirNum']]['fullName'], 'upload/'), 'size' => '-', 'mtime' => '-', 'url' => '#'));
}
while (isset($list['fileNum']) && $list['fileNum']) {
$list['fileNum']--;
array_push($res, array('type' => 'file', 'name' => $list['files'][$list['fileNum']]['Name'], 'path' => ltrim($list['files'][$list['fileNum']]['fullName'], 'upload/'), 'size' => format_bytes($list['files'][$list['fileNum']]['length'], ' '), 'mtime' => date('Y-m-d H:i:s', $list['files'][$list['fileNum']]['uploadTime']), 'url' => ltrim($list['files'][$list['fileNum']]['fullName'], 'upload/')));
}
return $res;
break;
case 'FTP':
$storage = new \Common\Plugin\Ftp();
$list = $storage->ls($path);
foreach ($list as &$item) {
$item['path'] = ltrim($item['path'], UPLOAD_PATH);
$item['url'] = str_replace('\\', '/', $item['path']);
}
return $list;
break;
default:
$path = realpath($path);
$path = str_replace(array('/', '\\'), DS, $path);
$list = glob($path . DS . '*');
$res = array();
foreach ($list as $key => $filename) {
array_push($res, array('type' => is_dir($filename) ? 'dir' : 'file', 'name' => basename($filename), 'path' => ltrim(str_replace(realpath(UPLOAD_PATH), '', $filename), DS), 'size' => format_bytes(filesize($filename), ' '), 'mtime' => date('Y-m-d H:i:s', filemtime($filename)), 'url' => ltrim(str_replace(array(realpath(UPLOAD_PATH), '\\'), array('', '/'), $filename), '/')));
}
return $res;
}
}