本文整理汇总了PHP中TemplateHelper::format_bytes方法的典型用法代码示例。如果您正苦于以下问题:PHP TemplateHelper::format_bytes方法的具体用法?PHP TemplateHelper::format_bytes怎么用?PHP TemplateHelper::format_bytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TemplateHelper
的用法示例。
在下文中一共展示了TemplateHelper::format_bytes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* Загрузка и обработка файла:
*/
public function process($board)
{
if (array_key_exists('upload', $_FILES) && $_FILES['upload']['error'] != 4) {
$kvs = KVS::getInstance();
$upload = $_FILES['upload'];
$pathinfo = pathinfo($upload['name']);
$data = array();
$data['board'] = $board;
$data['original_name'] = $upload['name'];
$data['size'] = TemplateHelper::format_bytes($upload['size']);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
switch (finfo_file($finfo, $upload['tmp_name'])) {
case 'image/jpeg':
case 'image/jpg':
$ext = 'jpg';
break;
case 'image/png':
$ext = 'png';
break;
case 'image/gif':
$ext = 'gif';
break;
default:
return false;
}
finfo_close($finfo);
$name = time() . rand(0, 100000);
copy($upload['tmp_name'], UPLOAD_PATH . '/' . $board . '/' . $name . '.' . $ext);
$data['file_name'] = $name . '.' . $ext;
$full_size = getimagesize(UPLOAD_PATH . '/' . $data['board'] . '/' . $data['file_name']);
$data['full_size'] = array($full_size[0], $full_size[1]);
$this->createThumbnail($upload['tmp_name'], UPLOAD_PATH . '/' . $board . '/thumb_' . $name . '.' . $ext);
$data['thumb_name'] = 'thumb_' . $name . '.' . $ext;
$thumb_size = getimagesize(UPLOAD_PATH . '/' . $data['board'] . '/' . $data['thumb_name']);
$data['thumb_size'] = array($thumb_size[0], $thumb_size[1]);
$data['web_full'] = 'uploads/' . $board . '/' . $data['file_name'];
$data['web_thumb'] = 'uploads/' . $board . '/' . $data['thumb_name'];
$this->data = $data;
}
/*
elseif (!empty($_POST['upload']))
{
$kvs = KVS::getInstance();
$upload = $_POST['upload'];
$data = array();
$data['board'] = $board;
$data['original_name'] = $upload['name'];
$data['size'] = TemplateHelper::format_bytes($upload['size']);
$uploader = new uploader();
$uploader -> destDir = UPLOAD_PATH .'/'. $board;
$uploader -> upload($upload['url']);
$data['file_name'] = $uploader -> fileName;
$full_size = getimagesize(UPLOAD_PATH .'/'. $data['board'] .'/'. $data['file_name']);
$data['full_size'] = array($full_size[0], $full_size[1]);
$uploader -> resizeDir = UPLOAD_PATH .'/'. $board .'/thumb_';
$data['thumb_name'] = 'thumb_'. $uploader -> resize('', min(125, $data['full_size'][0]), 200);
$thumb_size = getimagesize(UPLOAD_PATH .'/'. $data['board'] .'/'. $data['thumb_name']);
$data['thumb_size'] = array($thumb_size[0], $thumb_size[1]);
$data['web_full'] = 'uploads/'. $board .'/'. $data['file_name'];
$data['web_thumb'] = 'uploads/'. $board .'/'. $data['thumb_name'];
die;
}*/
return true;
}