本文整理汇总了PHP中tools::formatBytes方法的典型用法代码示例。如果您正苦于以下问题:PHP tools::formatBytes方法的具体用法?PHP tools::formatBytes怎么用?PHP tools::formatBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tools
的用法示例。
在下文中一共展示了tools::formatBytes方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: jsConfig
/**
* 加载js路径配置文件
* @param type $type 应用类型,web为旅行,blog为博客
*/
public function jsConfig($type = 'wedding', $module = 'web')
{
$arr['wedding'] = array('baseUrl' => zmf::config('baseurl'), 'hasLogin' => Yii::app()->user->isGuest ? 'false' : 'true', 'controller' => Yii::app()->getController()->id, 'action' => Yii::app()->getController()->getAction()->id, 'module' => $module, 'reputation' => 'false', 'loginHtml' => $this->renderPartial('//common/notLoginInfo', NULL, true), 'reportUrl' => zmf::config('domain') . Yii::app()->createUrl('/ajax/report'), 'delUploadImgUrl' => zmf::config('domain') . Yii::app()->createUrl('/attachments/delUploadImg'), 'csrfToken' => Yii::app()->request->csrfToken, 'currentSessionId' => Yii::app()->session->sessionID, 'allowImgTypes' => zmf::config('imgAllowTypes'), 'allowImgPerSize' => tools::formatBytes(zmf::config('imgMaxSize')), 'perAddImgNum' => zmf::config('imgUploadNum'), 'setStatusUrl' => zmf::config('domain') . Yii::app()->createUrl('/ajax/setstatus'), 'favorUrl' => zmf::config('domain') . Yii::app()->createUrl('/ajax/favor'), 'favoriteUrl' => zmf::config('domain') . Yii::app()->createUrl('/ajax/favorite'), 'searchUrl' => zmf::config('domain') . Yii::app()->createUrl('/search/suggest'), 'delPostUrl' => zmf::config('domain') . Yii::app()->createUrl('/del/delPost'), 'addTagsUrl' => zmf::config('domain') . Yii::app()->createUrl('/tags/foradd'), 'searchPage' => zmf::config('domain') . Yii::app()->createUrl('/search/index'), 'addCommentsUrl' => zmf::config('domain') . Yii::app()->createUrl('/ajax/comment'), 'checkReputationUrl' => zmf::config('domain') . Yii::app()->createUrl('/ajax/reputation'), 'cardLink_user' => zmf::config('domain') . Yii::app()->createUrl('/ajax/card', array('type' => 'user')), 'favorUserLink' => zmf::config('domain') . Yii::app()->createUrl('/ajax/favorUser'), 'feedbackUrl' => zmf::config('domain') . Yii::app()->createUrl('/feed/add'), 'redirectPoiUrl' => zmf::config('domain') . Yii::app()->createUrl('/ajax/redpoi'), 'combineCookieUrl' => zmf::config('domain') . Yii::app()->createUrl('/ajax/mergecookie'), 'rateJson' => Area::getRates(), 'joinGroupUrl' => zmf::config('domain') . Yii::app()->createUrl('/ajax/joinGroup'), 'contentsUrl' => zmf::config('domain') . Yii::app()->createUrl('/ajax/getContents'));
$attrs = $arr['wedding'];
$longHtml = '<script>var zmf={';
foreach ($attrs as $k => $v) {
$longHtml .= $k . ":'" . $v . "',";
}
$longHtml .= '};</script>';
echo $longHtml;
}
示例2: jsConfig
/**
* 加载js路径配置文件
* @param type $type 应用类型,web为旅行,blog为博客
*/
public function jsConfig($type = 'web', $module = 'web')
{
$arr['web'] = array('baseUrl' => zmf::config('baseurl'), 'hasLogin' => Yii::app()->user->isGuest ? 'false' : 'true', 'controller' => Yii::app()->getController()->id, 'action' => Yii::app()->getController()->getAction()->id, 'module' => $module, 'reputation' => 'false', 'loginHtml' => '', 'addCiUrl' => zmf::config('domain') . Yii::app()->createUrl('/ajax/addCi'), 'delCiUrl' => zmf::config('domain') . Yii::app()->createUrl('/ajax/delCi'), 'reportUrl' => zmf::config('domain') . Yii::app()->createUrl('/ajax/report'), 'delUploadImgUrl' => zmf::config('domain') . Yii::app()->createUrl('/attachments/delUploadImg'), 'csrfToken' => Yii::app()->request->csrfToken, 'currentSessionId' => Yii::app()->session->sessionID, 'allowImgTypes' => zmf::config('imgAllowTypes'), 'allowImgPerSize' => tools::formatBytes(zmf::config('imgMaxSize')), 'perAddImgNum' => zmf::config('imgUploadNum'), 'searchUrl' => zmf::config('domain') . Yii::app()->createUrl('/search/suggest'), 'searchPage' => zmf::config('domain') . Yii::app()->createUrl('/search/index'), 'commentsUrl' => zmf::config('domain') . Yii::app()->createUrl('/comments/lists'), 'addCommentsUrl' => zmf::config('domain') . Yii::app()->createUrl('/comments/add'), 'feedbackUrl' => zmf::config('domain') . Yii::app()->createUrl('/feed/add'));
$attrs = $arr[$type];
$longHtml = '<script>var zmf={';
foreach ($attrs as $k => $v) {
$longHtml .= $k . ":'" . $v . "',";
}
$longHtml .= '};</script>';
echo $longHtml;
}
示例3:
<textarea id="input_tmp" name="input_tmp" style="display: none"></textarea>
<input id="textareaid" type="hidden" value="<?php
echo CHtml::activeId($model, $attri);
?>
"/>
<script>
var tipImgUploadUrl="<?php
echo $upurl;
?>
";
var allowImgTypes="<?php
echo zmf::config('imgAllowTypes');
?>
";
var allowImgPerSize="<?php
echo tools::formatBytes(zmf::config('imgMaxSize'));
?>
";
var perAddImgNum="<?php
echo zmf::config('imgUploadNum');
?>
";
$(function(){
myeditor=UM.getEditor('<?php
echo CHtml::activeId($model, $attri);
?>
', {
//UMEDITOR_HOME_URL : URL,
toolbar: ["bold","italic","underline","link","unlink","image"],
lang:'zh-cn', //语言
wordCount:false, //关闭字数统计
示例4: actionSimpleUpload
/**
* 不入数据库的上传
* 不做压缩和缩略图处理
*/
public function actionSimpleUpload()
{
$uptype = zmf::filterInput($_GET['type'], 't', 1);
$fileholder = zmf::filterInput($_GET['fileholder'], 't', 1);
//上传控件的ID
$fileName = zmf::filterInput($_GET['fileName'], 't', 1);
//上传后保存名字
$keyid = zmf::filterInput($_GET['keyid']);
//所属对象ID
if (!isset($uptype) or !in_array($uptype, array('topArea', 'avatar'))) {
$this->jsonOutPut(0, '请设置上传所属类型' . $uptype);
}
if (Yii::app()->request->getParam('PHPSESSID')) {
Yii::app()->session->close();
Yii::app()->session->setSessionID(Yii::app()->request->getParam('PHPSESSID'));
Yii::app()->session->open();
}
if (Yii::app()->user->isGuest) {
$this->jsonOutPut(0, Yii::t('default', 'loginfirst'));
}
if ($uptype == 'avatar' && !$keyid) {
$this->jsonOutPut(0, '缺少参数');
}
$checkInfo = UserPower::check('addImage', true);
if (!$checkInfo['status']) {
$this->jsonOutPut(0, $checkInfo['msg']);
}
if (!$fileholder) {
$fileholder = 'filedata';
}
if (!isset($_FILES[$fileholder]) || !is_uploaded_file($_FILES[$fileholder]["tmp_name"]) || $_FILES[$fileholder]["error"] != 0) {
$this->jsonOutPut(0, '无效上传,请重试');
}
$img = CUploadedFile::getInstanceByName($fileholder);
$ext = $img->getExtensionName();
$size = $img->getSize();
if ($size > zmf::config('imgMaxSize')) {
$this->jsonOutPut(0, '上传文件最大尺寸为:' . tools::formatBytes(zmf::config('imgMaxSize')));
}
$upExt = zmf::config("imgAllowTypes");
if (!preg_match('/^(' . str_replace('*.', '|', str_replace(';', '', $upExt)) . ')$/i', $ext)) {
$this->jsonOutPut(0, '上传文件扩展名必需为:' . $upExt);
}
if (!$fileName) {
$fileName = uniqid() . '.' . $ext;
}
if ($uptype == 'avatar') {
$fileName = $keyid . '.jpg';
}
if ($uptype == 'topArea') {
$todir = zmf::attachBase('app') . '/daodao/';
$returnDir = zmf::attachBase('site') . '/daodao/';
} elseif ($uptype == 'avatar') {
$todir = zmf::attachBase('app') . '/avatar/origin/' . $keyid . '/';
$todir2 = zmf::attachBase('app') . '/avatar/big/' . $keyid . '/';
$todir3 = zmf::attachBase('app') . '/avatar/small/' . $keyid . '/';
$returnDir = zmf::attachBase('site') . '/avatar/small/' . $keyid . '/';
}
zmf::createUploadDir($todir);
if (move_uploaded_file($_FILES[$fileholder]["tmp_name"], $todir . $fileName)) {
if ($uptype == 'avatar') {
$image = Yii::app()->image->load($todir . $fileName);
zmf::createUploadDir($todir2);
zmf::createUploadDir($todir3);
$image->smart_resize(100, 100)->quality(95);
$image->save($todir2 . $fileName);
$image->smart_resize(50, 50)->quality(95);
$image->save($todir3 . $fileName);
}
$outPutData = array('status' => 1, 'imgsrc' => $returnDir . $fileName, 'attachid' => '');
$json = CJSON::encode($outPutData);
echo $json;
} else {
$this->jsonOutPut(0, '上传失败');
}
}
示例5: actionUpload
public function actionUpload()
{
$uptype = zmf::filterInput($_GET['type'], 't', 1);
$logid = zmf::filterInput($_GET['id']);
//所属对象
$reImgsize = zmf::filterInput($_GET['imgsize']);
//返回图片的尺寸
$fileholder = zmf::filterInput($_GET['fileholder'], 't', 1);
//上传控件的ID
if (!isset($uptype) or !in_array($uptype, array('posts', 'siteinfo'))) {
$this->jsonOutPut(0, '请设置上传所属类型' . $uptype);
}
if (Yii::app()->request->getParam('PHPSESSID')) {
Yii::app()->session->close();
$res = Yii::app()->session->setSessionID(Yii::app()->request->getParam('PHPSESSID'));
Yii::app()->session->open();
}
if (Yii::app()->user->isGuest) {
$this->jsonOutPut(0, '请先登录');
}
if (!$fileholder) {
$fileholder = 'filedata';
}
if (!isset($_FILES[$fileholder]) || !is_uploaded_file($_FILES[$fileholder]["tmp_name"]) || $_FILES[$fileholder]["error"] != 0) {
$this->jsonOutPut(0, '无效上传,请重试');
}
$img = CUploadedFile::getInstanceByName($fileholder);
$ext = $img->getExtensionName();
$size = $img->getSize();
if ($size > zmf::config('imgMaxSize')) {
$this->jsonOutPut(0, '上传文件最大尺寸为:' . tools::formatBytes(zmf::config('imgMaxSize')));
}
$upExt = zmf::config("imgAllowTypes");
if (!preg_match('/^(' . str_replace('*.', '|', str_replace(';', '', $upExt)) . ')$/i', $ext)) {
$this->jsonOutPut(0, '上传文件扩展名必需为:' . $upExt);
}
$sizeinfo = getimagesize($_FILES[$fileholder]["tmp_name"]);
if ($sizeinfo['0'] < zmf::config('imgMinWidth') or $sizeinfo[1] < zmf::config('imgMinHeight')) {
$this->jsonOutPut(0, "要求上传的图片尺寸,宽不能不小于" . zmf::config('imgMinWidth') . "px,高不能小于" . zmf::config('imgMinHeight') . "px.");
}
$ctime = zmf::now();
$dir = zmf::uploadDirs($ctime, 'app', $uptype);
zmf::createUploadDir($dir);
$fileName = zmf::uuid() . '.' . $ext;
$origin = $dir;
if (move_uploaded_file($_FILES[$fileholder]["tmp_name"], $origin . $fileName)) {
$data = array();
$status = Posts::STATUS_NOTPASSED;
$data['uid'] = zmf::uid();
$data['logid'] = $logid;
$data['filePath'] = $fileName;
$data['fileDesc'] = '';
$data['classify'] = $uptype;
$data['covered'] = '0';
$data['cTime'] = $ctime;
$data['status'] = $status;
$data['width'] = $sizeinfo[0];
$data['height'] = $sizeinfo[1];
$data['size'] = $size;
$model = new Attachments();
$model->attributes = $data;
if ($model->save()) {
$attachid = $model->id;
$returnImgDir = zmf::getUpExtraUrl($ctime);
$saveName = $uptype . '/' . $returnImgDir . '/' . $fileName;
$accessKey = zmf::config('qiniuAk');
$secretKey = zmf::config('qiniuSk');
$bucket = zmf::config('qiniuBucket');
if ($accessKey && $secretKey && $bucket) {
$auth = new Auth($accessKey, $secretKey);
$token = $auth->uploadToken($bucket);
$uploadMgr = new UploadManager();
list($ret, $err) = $uploadMgr->putFile($token, $saveName, $origin . $fileName);
if ($err !== null) {
zmf::fp(var_export($err));
$this->jsonOutPut(0, '上传至云服务错误');
}
}
$returnimg = zmf::uploadDirs($ctime, 'site', $uptype) . $fileName;
$returnimg = zmf::getThumbnailUrl($returnimg, '650', $uptype);
$_attr = array('id' => $attachid, 'imgurl' => $returnimg);
$html = '';
if ($uptype == 'posts') {
//$html= $this->renderPartial('/posts/_addImg',array('data'=>$_attr),true);
}
$outPutData = array('status' => 1, 'attachid' => $attachid, 'imgsrc' => $returnimg, 'html' => $html);
$json = CJSON::encode($outPutData);
echo $json;
} else {
$this->jsonOutPut(0, '写入数据库错误');
}
}
}
示例6: addPostImg
public function addPostImg()
{
$logid = zmf::filterInput($_GET['id']);
$uptype = zmf::filterInput($_GET['imgtype'], 't', 1);
if (!$uptype) {
$this->jsonOutPut(0, '不允许的分类');
}
if (!$logid) {
$logid = 0;
}
$ctime = time();
$dirs = zmf::upDirs($ctime, 'app', $uptype);
$origin = $dirs['origin'] . '/';
unset($dirs['origin']);
zmf::createUploadDir($origin);
$img = CUploadedFile::getInstanceByName('filedata');
if ($img->getHasError()) {
$this->jsonOutPut(0, '上传有误,请重试');
}
$ext = $img->getExtensionName();
$upExt = zmf::config("imgAllowTypes");
if (!preg_match('/^(' . str_replace('*.', '|', str_replace(';', '', $upExt)) . ')$/i', $ext)) {
$this->jsonOutPut(0, '上传文件扩展名必需为:' . $upExt);
}
$size = $img->getSize();
if ($size > zmf::config('imgMaxSize')) {
$this->jsonOutPut(0, '上传文件最大尺寸为:' . tools::formatBytes(zmf::config('imgMaxSize')));
}
$_imgInfo = getimagesize($_FILES["filedata"]["tmp_name"]);
if ($_imgInfo['0'] < zmf::config('imgMinWidth') or $_imgInfo[1] < zmf::config('imgMinHeight')) {
$this->jsonOutPut(0, "宽不能小于" . zmf::config('imgMinWidth') . "px<br/>高不能小于" . zmf::config('imgMinHeight') . "px");
}
$fileName = uniqid() . '.' . $ext;
// $_extra=self::getUpExtraUrl($ctime);
// $filePath=$_extra.'/'.$fileName;
if (move_uploaded_file($_FILES["filedata"]["tmp_name"], $origin . $fileName)) {
$uid = Yii::app()->user->id;
$uid = 1;
$data['uid'] = $uid;
$data['logid'] = $logid;
$data['filePath'] = $fileName;
$data['fileDesc'] = $fileName;
$data['classify'] = $uptype;
$data['covered'] = '0';
$data['cTime'] = $ctime;
$data['status'] = Posts::STATUS_DELED;
$model = new Attachments();
$model->attributes = $data;
if ($model->validate()) {
if (!$model->save()) {
$this->jsonOutPut(0, '写入数据库出错');
} else {
$attachid = $model->id;
}
} else {
$this->jsonOutPut(0, '数据验证错误');
}
$image = Yii::app()->image->load($origin . $fileName);
$_quality = zmf::config('imgQuality');
$quality = isset($quality) ? $quality : 100;
foreach ($dirs as $dk => $_dir) {
zmf::createUploadDir($_dir);
if ($_imgInfo[0] < $dk && $_imgInfo[1] < $dk) {
$image->resize($_imgInfo[0], $_imgInfo[1])->quality($quality);
} else {
$image->smart_resize($dk, ceil($dk * 0.75))->quality($quality);
}
$image->save($_dir . '/' . $fileName, false);
}
$_dir = zmf::upDirs($ctime, 'site', $uptype, '600');
$returnimg = $_dir . '/' . $fileName;
$data = array('imgsrc' => $returnimg, 'attachid' => $attachid);
$this->jsonOutPut(1, $data);
}
}
示例7: actionSimpleUpload
/**
* 不入数据库的上传
* 不做压缩和缩略图处理
*/
public function actionSimpleUpload()
{
$uptype = zmf::filterInput($_GET['type'], 't', 1);
$fileholder = zmf::filterInput($_GET['fileholder'], 't', 1);
//上传控件的ID
$fileName = zmf::filterInput($_GET['fileName'], 't', 1);
//上传后保存名字
$keyid = zmf::filterInput($_GET['keyid']);
//所属对象ID
if (!isset($uptype) or !in_array($uptype, array('avatar'))) {
$this->jsonOutPut(0, '请设置上传所属类型' . $uptype);
}
if (Yii::app()->request->getParam('PHPSESSID')) {
Yii::app()->session->close();
Yii::app()->session->setSessionID(Yii::app()->request->getParam('PHPSESSID'));
Yii::app()->session->open();
}
if (Yii::app()->user->isGuest) {
$this->jsonOutPut(0, Yii::t('default', 'loginfirst'));
}
// $checkInfo = UserPower::check('addImage', true);
// if (!$checkInfo['status']) {
// $this->jsonOutPut(0, $checkInfo['msg']);
// }
if (!$fileholder) {
$fileholder = 'filedata';
}
if (!isset($_FILES[$fileholder]) || !is_uploaded_file($_FILES[$fileholder]["tmp_name"]) || $_FILES[$fileholder]["error"] != 0) {
$this->jsonOutPut(0, '无效上传,请重试');
}
$img = CUploadedFile::getInstanceByName($fileholder);
$ext = $img->getExtensionName();
$size = $img->getSize();
if ($size > zmf::config('imgMaxSize')) {
$this->jsonOutPut(0, '上传文件最大尺寸为:' . tools::formatBytes(zmf::config('imgMaxSize')));
}
$upExt = zmf::config("imgAllowTypes");
if (!preg_match('/^(' . str_replace('*.', '|', str_replace(';', '', $upExt)) . ')$/i', $ext)) {
$this->jsonOutPut(0, '上传文件扩展名必需为:' . $upExt);
}
if (!$fileName) {
$fileName = uniqid() . '.' . $ext;
}
if ($uptype == 'avatar') {
$fileName = $keyid . '.jpg';
}
$ctime = zmf::now();
$dirs = zmf::uploadDirs($ctime, 'app', $uptype, null, true);
$fileName = uniqid() . '.' . $ext;
$origin = $dirs['origin'];
unset($dirs['origin']);
$fileNameWithoutDomain = zmf::getUpExtraUrl($ctime) . '/600_' . $fileName;
//相对于网站的存放路径
if (move_uploaded_file($_FILES[$fileholder]["tmp_name"], $origin . $fileName)) {
Yii::import('application.vendors.thinkphp.*');
require_once 'ImageGd.php';
foreach ($dirs as $dk => $_dir) {
$image = new ImageGd($origin . $fileName);
$image->thumb($dk, $dk, 'center');
$image->save($_dir . $fileName);
}
Users::model()->updateByPk($this->uid, array('avatar' => $fileNameWithoutDomain));
$imgsize = $reImgsize > 0 ? $reImgsize : 170;
$returnimg = zmf::uploadDirs($ctime, 'site', $uptype, $imgsize) . $fileName;
$outPutData = array('status' => 1, 'imgsrc' => $returnimg, 'attachid' => '');
$json = CJSON::encode($outPutData);
echo $json;
} else {
$this->jsonOutPut(0, '上传失败');
}
}