69 lines
2.5 KiB
PHP
Executable File
69 lines
2.5 KiB
PHP
Executable File
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
|
// +----------------------------------------------------------------------
|
|
// | Author: 流年 <liu21st@gmail.com>
|
|
// +----------------------------------------------------------------------
|
|
use think\facade\Env;
|
|
// 应用公共文件
|
|
|
|
if (!function_exists('get_middle_str')) {
|
|
/**
|
|
* 获取指定字符串中间内容
|
|
* @param string $str 原字符串
|
|
* @param string $leftStr 左侧
|
|
* @param string $rightStr
|
|
* @return bool|string
|
|
*/
|
|
function get_middle_str($str, $leftStr, $rightStr)
|
|
{
|
|
$left = strpos($str, $leftStr);
|
|
$right = strpos($str, $rightStr, $left);
|
|
if ($left < 0 || $right < $left) {
|
|
return '';
|
|
}
|
|
return substr($str, $left + strlen($leftStr), $right - $left - strlen($leftStr));
|
|
}
|
|
}
|
|
|
|
|
|
if (!function_exists('format_size')) {
|
|
/**
|
|
* 格式化文件大小单位
|
|
* @param $size
|
|
* @param string $delimiter
|
|
* @return string
|
|
*/
|
|
function format_size($size, $delimiter = '')
|
|
{
|
|
$units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
|
|
for ($i = 0; $size >= 1024 && $i < 5; $i++) {
|
|
$size /= 1024;
|
|
}
|
|
return round($size, 2) . $delimiter . $units[$i];
|
|
}
|
|
}
|
|
|
|
if (!function_exists('thumbnail_img')) {
|
|
/**
|
|
* 生成缩略图
|
|
* @param string $status 上传后图片信息
|
|
* @param string $width 宽
|
|
* @param string $heigh 高
|
|
*/
|
|
function thumbnail_img($status, $width, $heigh, $folder_name = '')
|
|
{
|
|
$img = Env::get('root_path') . 'public/uploads/attachment/' . $status->getSaveName();
|
|
$image = \think\Image::open($img);
|
|
$slt = substr($img, 0, strlen($img) - 4);
|
|
$image->thumb($width, $heigh, \think\Image::THUMB_CENTER)->save($slt . '_' . $width . '_' . $heigh . '.' . $status->getExtension());
|
|
$img_url = $status->getSaveName();
|
|
$img_slt = '/uploads/' . $folder_name . '/' . substr($img_url, 0, strlen($img_url) - 4) . '_' . $width . '_' . $heigh . '.' . $status->getExtension();
|
|
return $img_slt;
|
|
}
|
|
}
|