本文整理匯總了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;
}