EasyImages2.0/application/function.php

1322 lines
40 KiB
PHP
Raw Normal View History

<?php
2022-03-30 06:19:26 +00:00
2022-03-26 19:39:15 +00:00
/**
* EasyImage2.0 - 简单图床基础配置
* @author icret
* @email lemonim@qq.com
* @Github https://github.com/icret/easyImages2.0
* QQ Group 623688684
* @Last 2022-1-22 17:38:57
* 上传服务器后第一次打开会检查运行环境,请根据提示操作;
* 检查环境仅会在第一开始开始出现并在config目录下生成EasyImage.lock文件如需再次查看请删除此文件。
* 敬请注意本程序为开源程序你可以使用本程序在任何非商业项目或者网站中。但请你务必保留代码中相关信息页面logo和页面上必要的链接可以更改
* 本人仅为程序开源创作,如非法网站与本人无关,请勿用于非法用途
* 请为本人博客blog.png.cm加上网址链接谢谢支持。作为开发者你可以对相应的后台功能进行扩展增删改相应代码,但请保留代码中相关来源信息(例如:本人博客,邮箱等)
* 如果因安装问题或其他问题可以给我发邮件。
*/
/*---------------基础配置开始-------------------*/
// 设置html为utf8
2022-04-08 13:33:53 +00:00
header('Content-Type:text/html;charset=utf-8');
2022-03-26 19:39:15 +00:00
//将时区设置为中国·上海
2022-04-08 13:33:53 +00:00
ini_set('date.timezone', 'Asia/Shanghai');
date_default_timezone_set('Asia/Shanghai');
2022-03-26 19:39:15 +00:00
// 修改内存限制 根据服务器配置选择低于128M容易出现上传失败你懂得图片挺占用内存的
2022-04-08 13:33:53 +00:00
ini_set('memory_limit', '512M');
2022-03-26 19:39:15 +00:00
// 定义根目录
2022-04-08 13:33:53 +00:00
define('APP_ROOT', str_replace('\\', '/', realpath(dirname(__FILE__) . '/../')));
2022-03-26 19:39:15 +00:00
// 判断当前的系统类型是否为windows
2022-04-08 13:33:53 +00:00
define('IS_WIN', strstr(PHP_OS, 'WIN') ? 1 : 0);
2022-03-26 19:39:15 +00:00
/*---------------基础配置结束-------------------*/
2021-11-09 03:43:23 +00:00
require_once APP_ROOT . '/config/config.php';
2022-01-27 09:25:46 +00:00
require_once APP_ROOT . '/config/config.guest.php';
2022-01-27 09:25:46 +00:00
/**
* 判断GIF图片是否为动态
* @param $filename string 文件
2022-03-07 04:34:04 +00:00
* @return int |
2022-01-27 09:25:46 +00:00
*/
function isAnimatedGif($filename)
{
2022-01-12 18:48:08 +00:00
$fp = fopen($filename, 'rb');
$filecontent = fread($fp, filesize($filename));
fclose($fp);
return strpos($filecontent, chr(0x21) . chr(0xff) . chr(0x0b) . 'NETSCAPE2.0') === FALSE ? 0 : 1;
}
2022-01-27 09:25:46 +00:00
/**
* 校验登录
*/
function checkLogin()
{
2022-01-27 09:25:46 +00:00
global $guestConfig;
2022-01-12 18:48:08 +00:00
global $config;
2022-01-27 09:25:46 +00:00
// 无cookie
if (empty($_COOKIE['auth'])) {
2022-04-11 05:35:48 +00:00
return 201;
2022-01-12 18:48:08 +00:00
}
2022-01-27 09:25:46 +00:00
2022-04-11 05:35:48 +00:00
// 存在cookie
2022-01-27 09:25:46 +00:00
if (isset($_COOKIE['auth'])) {
2022-04-11 05:35:48 +00:00
2022-01-27 09:25:46 +00:00
$getCOK = unserialize($_COOKIE['auth']);
2022-01-12 18:48:08 +00:00
2022-04-11 05:35:48 +00:00
// 无法读取cookie
2022-01-27 09:25:46 +00:00
if (!$getCOK) {
2022-04-11 05:35:48 +00:00
return 202;
2022-01-12 18:48:08 +00:00
}
2022-04-11 05:35:48 +00:00
// 密码错误
2022-05-03 05:00:40 +00:00
if ($getCOK[1] !== $config['password'] && $getCOK[1] !== $guestConfig[$getCOK[0]]['password']) {
2022-04-11 05:35:48 +00:00
return 203;
}
2022-05-03 05:00:40 +00:00
2022-04-11 05:35:48 +00:00
// 管理员登陆
if ($getCOK[1] == $config['password']) {
return 204;
}
// 上传者账号登陆
2022-05-03 05:00:40 +00:00
if ($getCOK[1] == $guestConfig[$getCOK[0]]['password']) {
if ($guestConfig[$getCOK[0]]['expired'] < time()) {
// 上传者账号过期
return 206;
}
2022-04-11 05:35:48 +00:00
return 205;
2022-01-27 09:25:46 +00:00
}
2022-01-12 18:48:08 +00:00
}
2022-01-05 10:41:45 +00:00
}
2022-01-12 18:48:08 +00:00
2022-01-27 09:25:46 +00:00
/**
* 仅允许登录后上传
*/
function mustLogin()
{
2022-01-12 18:48:08 +00:00
global $config;
if ($config['mustLogin']) {
2022-04-11 05:35:48 +00:00
switch (checkLogin()) {
case 201:
echo '
<script>
new $.zui.Messager("本站已开启登陆上传, 请登录!", {
type: "danger", // 定义颜色主题
icon: "bullhorn" // 定义消息图标
}).show();
</script>';
header("refresh:2;url=" . $config['domain'] . "/admin/index.php");
break;
case 202:
echo '
<script>
new $.zui.Messager("登陆超时,请重新登录", {
type: "special", // 定义颜色主题
icon: "exclamation-sign" // 定义消息图标
}).show();
</script>';
header("refresh:2;url=" . $config['domain'] . "/admin/index.php");
break;
case 203:
echo '
<script>
new $.zui.Messager("密码已更改,请重新登录", {
type: "special", // 定义颜色主题
icon: "exclamation-sign" // 定义消息图标
}).show();
</script>';
exit(header("refresh:2;url=" . $config['domain'] . "/admin/index.php"));
break;
case 205:
echo '
<script>
2022-05-03 05:00:40 +00:00
new $.zui.Messager("上传者账户已登陆", {
2022-04-11 05:35:48 +00:00
type: "success", // 定义颜色主题
icon: "check", // 定义消息图标
placement:"bottom-right" // 消息位置
}).show();
</script>';
break;
2022-05-03 05:00:40 +00:00
case 206:
echo '
<script>
new $.zui.Messager("上传者账户已过期", {
type: "special", // 定义颜色主题
icon: "exclamation-sign" // 定义消息图标
}).show();
</script>';
break;
2022-04-11 05:35:48 +00:00
case 204:
echo '
<script>
new $.zui.Messager("管理员已登陆", {
type: "success", // 定义颜色主题
icon: "check", // 定义消息图标
placement:"bottom-right" // 消息位置
}).show();
</script>';
break;
}
2022-01-12 18:48:08 +00:00
}
}
2022-01-27 09:25:46 +00:00
/**
* 检查配置文件中目录是否存在是否可写并创建相应目录
* @param null $path 要创建的路径
* @return string
*/
function config_path($path = null)
{
2022-01-12 18:48:08 +00:00
global $config;
// php5.6 兼容写法:
$path = isset($path) ? $path : date('Y/m/d/');
// php7.0 $path = $path ?? date('Y/m/d/');
$img_path = $config['path'] . $path;
2022-01-12 18:48:08 +00:00
if (!is_dir($img_path)) {
@mkdir($img_path, 0755, true);
}
2022-01-12 18:48:08 +00:00
if (!is_writable($img_path)) {
@chmod($img_path, 0755);
}
2022-01-31 19:51:02 +00:00
2022-01-12 18:48:08 +00:00
return $img_path;
}
2022-01-27 09:25:46 +00:00
/**
* 图片命名规则
* @param null $source 源文件名称
* @return false|int|string|null
*/
2022-01-03 22:31:05 +00:00
function imgName($source = null)
{
2022-01-12 18:48:08 +00:00
global $config;
function create_guid() // guid生成函数
{
if (function_exists('com_create_guid') === true) {
return trim(com_create_guid(), '{}');
}
2022-03-16 07:18:32 +00:00
return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
2022-01-12 18:48:08 +00:00
}
switch ($config['imgName']) {
2022-03-16 07:18:32 +00:00
case "source":
// 以上传文件名称 例微信图片_20211228214754
2022-01-12 18:48:08 +00:00
// 过滤非法名称 $source = preg_replace("/\/|\~|\!|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\_|\+|\{|\}|\:|\<|\>|\?|\[|\]|\,|\.|\/|\;|\'|\`|\-|\=|\\\|\|/","",$source);
return $source;
break;
2022-03-16 07:18:32 +00:00
case "date":
// 以上传时间 例192704
2022-01-12 18:48:08 +00:00
return date("His");
break;
2022-03-16 07:18:32 +00:00
case "unix":
// 以Unix时间 例1635074840
2022-01-12 18:48:08 +00:00
return time();
break;
2022-03-16 07:18:32 +00:00
case "uniqid":
// 基于以微秒计的当前时间 例6175436c73418
2022-01-12 18:48:08 +00:00
return uniqid(true);
break;
2022-03-16 07:18:32 +00:00
case "guid":
// 全球唯一标识符 例6EDAD0CC-AB0C-4F61-BCCA-05FAD65BF0FA
2022-01-12 18:48:08 +00:00
return create_guid();
break;
2022-03-16 07:18:32 +00:00
case "md5":
// md5加密时间 例3888aa69eb321a2b61fcc63520bf6c82
2022-01-12 18:48:08 +00:00
return md5(microtime());
break;
2022-03-16 07:18:32 +00:00
case "sha1":
// sha1加密微秒 例654faac01499e0cb5fb0e9d78b21e234c63d842a
2022-01-12 18:48:08 +00:00
return sha1(microtime());
break;
2022-03-16 07:18:32 +00:00
case "crc32":
// crc32加密微秒 例2495551279
return crc32(microtime());
break;
2022-01-12 18:48:08 +00:00
default:
2022-03-16 07:18:32 +00:00
// 将上传时间+随机数转换为36进制 例vx77yu
return base_convert(date('His') . mt_rand(1001, 9999), 10, 36);
2022-01-12 18:48:08 +00:00
}
}
2022-01-27 09:25:46 +00:00
/**
* 静态文件CDN
*/
function static_cdn()
{
2022-01-12 18:48:08 +00:00
global $config;
if ($config['static_cdn']) {
echo $config['static_cdn_url'];
2022-01-27 09:25:46 +00:00
} else {
echo $config['domain'];
2022-01-12 18:48:08 +00:00
}
}
2022-03-07 04:34:04 +00:00
/**
* 获取允许上传的扩展名
*/
function getExtensions()
{
2022-01-12 18:48:08 +00:00
global $config;
2022-03-07 04:34:04 +00:00
$arr = explode(',', $config['extensions']);
2022-01-12 18:48:08 +00:00
$mime = '';
2022-03-07 04:34:04 +00:00
for ($i = 0; $i < count($arr); $i++) {
$mime .= $arr . ',';
2022-01-12 18:48:08 +00:00
}
return rtrim($mime, ',');
}
2022-01-12 18:48:08 +00:00
2022-01-27 09:25:46 +00:00
/**
* 获取目录大小 如果目录文件较多将很费时
* @param $path string 路径
* @return int
*/
function getDirectorySize($path)
{
2022-01-12 18:48:08 +00:00
$bytestotal = 0;
$path = realpath($path);
if ($path !== false && $path != '' && file_exists($path)) {
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object) {
$bytestotal += $object->getSize();
}
}
return $bytestotal;
}
/**
* 获取指定文件夹文件数量
* @param $dir 传入一个路径如:/apps/web
* @return int 返回文件数量
*/
function getFileNumber($dir)
{
2022-01-12 18:48:08 +00:00
$num = 0;
$arr = glob($dir);
foreach ($arr as $v) {
if (is_file($v)) {
$num++;
} else {
$num += getFileNumber($v . "/*");
}
}
return $num;
}
2022-01-27 09:25:46 +00:00
/**
* 图片展示页面
* getDir()取文件夹列表getFile()取对应文件夹下面的文件列表,二者的区别在于判断有没有“.”后缀的文件,其他都一样
* 获取文件目录列表,该方法返回数组
2022-01-27 09:25:46 +00:00
* @param $dir string 路径
* @return mixed
* @example getDir("./dir")
*/
2022-04-02 10:10:17 +00:00
function getDirList($dir)
{
2022-01-12 18:48:08 +00:00
$dirArray[] = NULL;
if (false != ($handle = opendir($dir))) {
$i = 0;
while (false !== ($file = readdir($handle))) {
//去掉"“.”、“..”以及带“.xxx”后缀的文件
if ($file != "." && $file != ".." && !strpos($file, ".")) {
$dirArray[$i] = $file;
$i++;
}
}
//关闭句柄
closedir($handle);
}
return $dirArray;
}
2022-01-12 18:48:08 +00:00
2022-01-27 09:25:46 +00:00
/**
* 获取文件列表
* @param $dir string 目录
* @return mixed
*/
function getFile($dir)
{
2022-01-12 18:48:08 +00:00
$fileArray[] = NULL;
if (is_dir($dir)) {
if (false != ($handle = opendir($dir))) {
$i = 0;
while (false !== ($file = readdir($handle))) {
//去掉"“.”、“..”以及带“.xxx”后缀的文件
if ($file != "." && $file != ".." && strpos($file, ".")) {
$fileArray[$i] = $file;
if ($i == 1000) {
break;
}
$i++;
}
}
//关闭句柄
closedir($handle);
}
}
return $fileArray;
}
2022-01-27 09:25:46 +00:00
/**
* 获取文件夹文件列表或数量
* @param string $dir_fileName_suffix 获取文件列表:目录+文件名*:全匹配+文件后缀 *: 全匹配 {jpg,png,gif}:匹配指定格式
* 递归文件数量:目录
* @example get_file_by_glob(__DIR__ . '/i/thumbnails/*.*', $type = 'list'); // 获取目录文件列表
* @example get_file_by_glob(__DIR__ . '/i/', $type = 'number'); // 递归获取文件夹数量
* @param string $type list|number 返回列表还是数量
* @return array|int 返回数组|数量
*/
function get_file_by_glob($dir_fileName_suffix, $type = 'list')
{
2022-02-17 16:13:13 +00:00
global $config;
2022-01-27 09:25:46 +00:00
// 获取所有文件
if ($type == 'list') {
2022-04-02 10:10:17 +00:00
$glob = glob($dir_fileName_suffix, GLOB_BRACE);
if ($glob) {
foreach ($glob as $v) {
if (is_file($v)) $res[] = basename($v);
2022-02-17 16:13:13 +00:00
}
2022-04-02 10:10:17 +00:00
// 排序
if ($res) {
switch ($config['showSort']) {
case 1:
$res = array_reverse($res);
break;
}
}
} else {
$res = array();
2022-02-17 16:13:13 +00:00
}
2022-01-27 09:25:46 +00:00
}
if ($type == 'number') {
$res = 0;
$glob = glob($dir_fileName_suffix); //把该路径下所有的文件存到一个数组里面;
2022-04-02 10:10:17 +00:00
if ($glob) {
foreach ($glob as $v) {
if (is_file($v)) {
$res++;
} else {
$res += get_file_by_glob($v . "/*", $type = 'number');
}
2022-01-27 09:25:46 +00:00
}
2022-04-11 05:35:48 +00:00
} else {
2022-04-02 10:10:17 +00:00
$res = 0;
2022-01-27 09:25:46 +00:00
}
}
return $res;
}
/**
* 递归函数实现遍历指定文件下的目录与文件数量
* 用来统计一个目录下的文件和目录的个数
* echo "目录数为:{$dirn}<br>";
* echo "文件数为:{$filen}<br>";
2022-01-27 09:25:46 +00:00
* @param $file string 目录
*/
function getdirnum($file)
{
2022-01-12 18:48:08 +00:00
$dirn = 0; //目录数
$filen = 0; //文件数
$dir = opendir($file);
while ($filename = readdir($dir)) {
if ($filename != "." && $filename != "..") {
$filename = $file . "/" . $filename;
if (is_dir($filename)) {
$dirn++;
getdirnum($filename);
//递归,就可以查看所有子目录
} else {
$filen++;
}
}
}
closedir($dir);
}
2022-01-27 09:25:46 +00:00
/**
* 把文件或目录的大小转化为容易读的方式
* disk_free_space - 磁盘可用空间(比如填写D盘某文件夹则会现在D盘剩余空间
* disk_total_space 磁盘总空间(比如填写D盘某文件夹则会现在D盘总空间
2022-01-27 09:25:46 +00:00
* @param $number
* @return string
*/
function getDistUsed($number)
{
2022-01-12 18:48:08 +00:00
$dw = ''; // 指定文件或目录统计的单位方式
if ($number > pow(2, 30)) {
$dw = "GB";
$number = round($number / pow(2, 30), 2);
} else if ($number > pow(2, 20)) {
$dw = "MB";
$number = round($number / pow(2, 20), 2);
} else if ($number > pow(2, 10)) {
$dw = "KB";
$number = round($number / pow(2, 10), 2);
} else {
$dw = "bytes";
}
return $number . $dw;
}
2022-01-27 09:25:46 +00:00
/**
* 根据url填写active
* @param $url string 要过滤的链接
* @return string
*/
function getActive($url)
{
2022-01-12 18:48:08 +00:00
$arr = $_SERVER['SCRIPT_NAME'];
if (strpos($arr, $url)) {
2022-02-06 07:39:57 +00:00
return ' class="active"';
2022-01-12 18:48:08 +00:00
}
}
2022-01-27 09:25:46 +00:00
/**
* 加密/解密图片路径
* @param string $data 要加密的内容
* @param int $mode =1或0 1解密 0加密
2022-03-14 09:52:21 +00:00
* @param String $key
*/
2022-03-14 09:52:21 +00:00
function urlHash($data, $mode, $key = null)
{
2022-01-12 18:48:08 +00:00
global $config;
2022-03-14 09:52:21 +00:00
2022-04-29 08:47:23 +00:00
if (!$key) {
2022-03-14 09:52:21 +00:00
$key = $config['password'];
}
2022-01-12 18:48:08 +00:00
$iv = 'sciCuBC7orQtDhTO';
if ($mode) {
return openssl_decrypt(base64_decode($data), "AES-128-CBC", $key, 0, $iv);
} else {
return base64_encode(openssl_encrypt($data, "AES-128-CBC", $key, 0, $iv));
}
}
2022-01-27 09:25:46 +00:00
/**
* 删除指定文件
* @param $url string 文件
* @param $type string 模式
*/
function getDel($url, $type)
{
2022-01-12 18:48:08 +00:00
global $config;
// url本地化
2022-05-03 05:00:40 +00:00
$url = htmlspecialchars(str_replace($config['domain'], '', $url)); // 过滤html 获取url path
2022-01-12 18:48:08 +00:00
$url = urldecode(trim($url));
if ($type == 'url') {
$url = $_SERVER['DOCUMENT_ROOT'] . $url;
}
if ($type == 'hash') {
$url = APP_ROOT . $url;
}
// 文件是否存在
if (is_file($url)) {
// 执行删除
if (@unlink($url)) {
echo '
<script>
2022-01-19 10:56:59 +00:00
new $.zui.Messager("删除成功", {
type: "success", // 定义颜色主题
icon: "ok-sign" // 定义消息图标
}).show();
// 延时2s跳转
// window.setTimeout("window.location=\'/../ \'",3500);
</script>
';
2022-01-12 18:48:08 +00:00
} else {
echo '
<script>
2022-01-19 10:56:59 +00:00
new $.zui.Messager("删除失败", {
type: "black", // 定义颜色主题
icon: "exclamation-sign" // 定义消息图标
}).show();
</script>
';
2022-01-12 18:48:08 +00:00
}
} else {
echo '
<script>
2022-01-19 10:56:59 +00:00
new $.zui.Messager("文件不存在", {
type: "danger", // 定义颜色主题
icon: "question-sign" // 定义消息图标
}).show();
</script>
';
2022-01-12 18:48:08 +00:00
}
// 清除查询
clearstatcache();
}
2022-01-27 09:25:46 +00:00
/**
* 判断是否此用户登录
* @param $user string 需要判断的用户名
* @return bool |
*/
function is_who_login($user)
{
2022-01-12 18:48:08 +00:00
global $config;
2022-01-27 09:25:46 +00:00
global $guestConfig;
2022-03-26 19:39:15 +00:00
if (isset($_COOKIE['auth'])) {
$getCOK = unserialize($_COOKIE['auth']);
2022-04-11 05:35:48 +00:00
if (!$getCOK) {
return false;
}
2022-03-26 19:39:15 +00:00
if ($user == 'admin') {
if ($getCOK[1] == $config['password']) return true;
}
if ($user == 'guest') {
if ($getCOK[0] !== $guestConfig[$getCOK[0]]) return true;
}
2022-01-12 18:48:08 +00:00
}
2022-03-26 19:39:15 +00:00
2022-01-27 09:25:46 +00:00
return false;
}
2022-01-12 18:48:08 +00:00
/**
* 检查PHP缺少简单图床必备的扩展
* 需检测的扩展:'fileinfo', 'iconv', 'gd', 'mbstring', 'openssl','zip',
* zip 扩展不是必须的但会影响tinyfilemanager文件压缩(本次不检测)
2022-01-12 18:48:08 +00:00
*
* 检测是否更改默认域名
2022-01-12 18:48:08 +00:00
*
* 检测是否修改默认密码
2022-01-27 09:25:46 +00:00
* @param $mode bool 是否开启检测
*/
function checkEnv($mode)
{
2022-01-12 18:48:08 +00:00
// 初始化安装
if (!is_file(APP_ROOT . '/install/install.lock') and is_file(APP_ROOT . '/install/install.php')) {
echo '<script type="text/javascript">window.location.href="' . get_whole_url('/') . '/install/index.php"</script>';
2022-01-12 18:48:08 +00:00
}
2021-11-09 03:43:23 +00:00
2022-01-12 18:48:08 +00:00
if ($mode) {
require_once __DIR__ . '/check.php';
}
}
2022-01-27 09:25:46 +00:00
/**
* 前端改变图片长宽
* @return string 裁剪参数
*/
function imgRatio()
{
2022-01-12 18:48:08 +00:00
global $config;
if ($config['imgRatio']) {
if ($config['imgRatio_crop'] === 1) {
$imgRatio_crop = 'true';
} else {
$imgRatio_crop = 'false';
}
if ($config['imgRatio_preserve_headers'] === 1) {
$imgRatio_preserve_headers = 'true';
} else {
$imgRatio_preserve_headers = 'false';
}
if ($config['image_x'] != 0) {
$image_x = "width:" . $config['image_x'] . ',';
} else {
$image_x = null;
}
if ($config['image_y'] != 0) {
$image_y = "height:" . $config['image_y'] . ',';
} else {
$image_y = null;
}
return '
resize:{
2022-01-03 12:04:27 +00:00
' . $image_x . '
' . $image_y . '
2022-01-01 07:40:23 +00:00
crop: ' . $imgRatio_crop . ',
quality:' . $config['imgRatio_quality'] . ',
preserve_headers: ' . $imgRatio_preserve_headers . ',
}';
2022-01-12 18:48:08 +00:00
} else {
return "file_data_name:'file'";
}
}
/**
* 定时获取GitHub 最新版本
2022-01-27 09:25:46 +00:00
* @return mixed|null 读取版本信息
*/
function getVersion()
{
2022-01-12 18:48:08 +00:00
global $config;
if ($config['checkEnv']) {
2022-01-21 09:57:44 +00:00
2022-01-12 18:48:08 +00:00
require_once APP_ROOT . '/application/class.version.php';
2022-01-21 11:09:31 +00:00
// 获取版本地址
$url = "https://api.github.com/repositories/188228357/releases/latest";
$getVersion = new getVerson($url);
$now = date('dH'); // 当前日期时间
$get_ver_day = array('1006', '2501'); // 检测日期的时间
foreach ($get_ver_day as $day) {
if (empty($getVersion->readJson())) { // 不存在就下载
$getVersion->downJson();
} else if ($day == $now) { // 是否在需要更新的日期
$getVersion->downJson();
/*
2022-01-12 18:48:08 +00:00
} elseif ($config['version'] == $getVersion->readJson()) { // 版本相同不提示
return null;
*/
2022-01-21 11:09:31 +00:00
} else { // 返回版本
return $getVersion->readJson();
2022-01-12 18:48:08 +00:00
}
}
}
2022-01-21 09:57:44 +00:00
return null;
}
2022-01-27 09:25:46 +00:00
/**
* 删除非空目录
* @param $dir string 要删除的目录
* @return bool true|false
*/
function deldir($dir)
{
2022-01-12 18:48:08 +00:00
if (file_exists($dir)) {
$files = scandir($dir);
foreach ($files as $file) {
if ($file != '.' && $file != '..') {
$path = $dir . '/' . $file;
if (is_dir($path)) {
deldir($path);
} else {
unlink($path);
}
}
}
rmdir($dir);
return true;
} else {
return false;
}
}
2021-10-30 09:19:15 +00:00
2022-01-27 09:25:46 +00:00
/**
* 图片监黄curl 访问网站并返回解码过的json信息
* @param $img string 图片url
* @param null $url 访问的网址
* @return mixed
*/
2022-01-12 18:48:08 +00:00
function moderatecontent_json($img, $url = null)
{
global $config;
if (empty($config['moderatecontent_key'])) {
exit;
}
$url = 'https://api.moderatecontent.com/moderate/?key=' . $config['moderatecontent_key'] . '&url=' . $img;
$headerArray = array("Content-type:application/json;", "Accept:application/json");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
2022-02-04 12:28:33 +00:00
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
2022-01-12 18:48:08 +00:00
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36');
$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output, true);
return $output;
2021-10-30 09:19:15 +00:00
}
2022-01-12 18:48:08 +00:00
2022-01-31 19:51:02 +00:00
/**
* 使用curl方式实现get或post请求
* @param $url 请求的url地址
* @param $data 发送的post数据 如果为空则为get方式请求
* return 请求后获取到的数据
*/
function nsfwjs_json($url, $data = '')
{
global $config;
if (empty($config['nsfwjs_url'])) {
exit;
}
$ch = curl_init();
$params[CURLOPT_URL] = $config['nsfwjs_url'] . $url; //请求url地址
$params[CURLOPT_HEADER] = false; //是否返回响应头信息
$params[CURLOPT_RETURNTRANSFER] = true; //是否将结果返回
$params[CURLOPT_FOLLOWLOCATION] = true; //是否重定向
$params[CURLOPT_TIMEOUT] = 30; //超时时间
if (!empty($data)) {
$params[CURLOPT_POST] = true;
$params[CURLOPT_POSTFIELDS] = $data;
}
$params[CURLOPT_SSL_VERIFYPEER] = false; //请求https时设置,还有其他解决方案
$params[CURLOPT_SSL_VERIFYHOST] = false; //请求https时,其他方案查看其他博文
curl_setopt_array($ch, $params); //传入curl参数
$content = curl_exec($ch); //执行
curl_close($ch); //关闭连接
$content = json_decode($content, true);
return $content;
}
2022-01-27 09:25:46 +00:00
/**
* 检查图片是否违规
2022-03-07 04:34:04 +00:00
* @param $imageUrl 图片链接
* @param int $type 模式: 1|moderatecontent 2|nsfwjs 3|移入回收站
* @param string $dir 移入的目录
* @return bool
2022-01-27 09:25:46 +00:00
*/
2022-02-27 06:59:03 +00:00
function checkImg($imageUrl, $type = 1, $dir = 'suspic/')
2021-10-30 09:19:15 +00:00
{
2022-01-12 18:48:08 +00:00
global $config;
2021-10-30 09:19:15 +00:00
2022-01-31 19:51:02 +00:00
/** # 使用moderatecontent */
if ($type == 1) {
$response = moderatecontent_json($imageUrl);
if ($response['rating_index'] == 3 or $response['predictions']['adult'] > $config['checkImg_value']) { // (1 = everyone, 2 = teen, 3 = adult)
$bad_pic = true;
}
}
2021-10-30 09:19:15 +00:00
2022-01-31 19:51:02 +00:00
/** # 使用nsfwjs */
if ($type == 2) {
/**
* probability概率
* className类型
*
* 上传图片后,总共会返回 5 个维度的数值来鉴别该图片的尺度:
*
* 绘画Drawing—— 无害的艺术,或艺术绘画;
* 变态Hentai—— 色情艺术,不适合大多数工作环境;
* 中立Neutral—— 一般,无害的内容;
* 色情Porn—— 不雅的内容和行为,通常涉及生殖器;
* 性感Sexy—— 不合时宜的挑衅内容。
*
* 当porn评分超过>=0.6左右,就几乎是一张带有色情性质的图片了。
*/
$file = nsfwjs_json($imageUrl);
// 将获取的值删除className后组建数组
for ($i = 0; $i <= count($file); $i++) {
if ($file[$i]['className'] == 'Drawing') {
$res['Drawing'] = $file[$i]['probability'];
}
if ($file[$i]['className'] == 'Hentai') {
$res['Hentai'] = $file[$i]['probability'];
}
if ($file[$i]['className'] == 'Neutral') {
$res['Neutral'] = $file[$i]['probability'];
}
if ($file[$i]['className'] == 'Porn') {
$res['Porn'] = $file[$i]['probability'];
}
if ($file[$i]['className'] == 'Sexy') {
$res['Sexy'] = $file[$i]['probability'];
}
}
// 测试数组是否正确
// foreach ($file as $k => $v) {
// foreach ($v as $k1 => $v1) {
// echo $k1 . '=>' . $v1 . '<br/>';
// }
// }
if ($res['Sexy'] * 100 > $config['checkImg_value'] or $res['Porn'] * 100 > $config['checkImg_value']) {
$bad_pic = true;
}
}
2022-02-23 03:12:10 +00:00
// 移入回收站
if ($type == 3) {
$bad_pic = true;
2022-02-27 06:59:03 +00:00
$dir = 'recycle/';
2022-02-23 03:12:10 +00:00
}
2022-01-31 19:51:02 +00:00
/** # 如果违规则移动图片到违规文件夹 */
if ($bad_pic == true) {
2022-05-03 05:00:40 +00:00
// $old_path = APP_ROOT . str_replace($config['domain'], '', $imageUrl); // 提交网址中的文件路径 /i/2021/10/29/p8vypd.png
$old_path = APP_ROOT . parse_url($imageUrl)['path']; // 提交网址中的文件路径 /i/2021/10/29/p8vypd.png
2022-01-31 19:51:02 +00:00
$name = date('Y_m_d') . '_' . basename($imageUrl); // 文件名 2021_10_30_p8vypd.png
2022-03-07 04:34:04 +00:00
$new_path = APP_ROOT . $config['path'] . $dir . $name; // 新路径含文件名
$suspic_dir = APP_ROOT . $config['path'] . $dir; // suspic路径
2022-01-31 19:51:02 +00:00
2022-03-07 04:34:04 +00:00
if (!is_dir($suspic_dir)) { // 创建suspic目录并移动
2022-02-04 12:28:33 +00:00
mkdir($suspic_dir, 0777, true);
2022-01-12 18:48:08 +00:00
}
2022-03-07 04:34:04 +00:00
if (is_file($old_path)) {
rename($old_path, $new_path);
return true;
} else {
return false;
}
2022-01-12 18:48:08 +00:00
}
2021-10-30 09:19:15 +00:00
}
2021-10-30 15:00:32 +00:00
2022-01-27 09:25:46 +00:00
/**
* 还原被审查的图片
* @param $name string 要还原的图片
*/
2022-02-27 06:59:03 +00:00
function re_checkImg($name, $dir = 'suspic/')
2021-10-30 15:00:32 +00:00
{
2022-01-12 18:48:08 +00:00
global $config;
2021-10-30 15:00:32 +00:00
2022-02-27 06:59:03 +00:00
$fileToPath = str_replace('_', '/', $name); // 将图片名称还原为带路径的名称eg:2021_11_03_pbmn1a.jpg =>2021/11/03/pbmn1a.jpg
$now_path_file = APP_ROOT . $config['path'] . $dir . $name; // 当前图片绝对位置 */i/suspic/2021_10_30_p8vypd.png
if (is_file($now_path_file)) {
2022-02-27 06:59:03 +00:00
$to_file = APP_ROOT . $config['path'] . $fileToPath; // 要还原图片的绝对位置 */i/2021/10/30/p8vypd.png
rename($now_path_file, $to_file); // 移动文件
2022-01-31 19:51:02 +00:00
return true;
}
2021-10-30 15:00:32 +00:00
}
2022-01-12 18:48:08 +00:00
2022-01-27 09:25:46 +00:00
/**
* 创建缩略图
* @param $imgName string 需要创建缩略图的名称
*/
2022-01-01 07:40:23 +00:00
function creat_thumbnail_images($imgName)
2021-11-09 03:43:23 +00:00
{
2022-01-12 18:48:08 +00:00
require_once __DIR__ . '/class.thumb.php';
global $config;
2021-11-09 03:43:23 +00:00
2022-01-30 00:07:26 +00:00
$old_img_path = APP_ROOT . config_path() . $imgName; // 获取要创建缩略图文件的绝对路径
$cache_path = APP_ROOT . $config['path'] . 'thumbnails/'; // cache目录的绝对路径
2021-11-16 04:57:14 +00:00
2022-01-30 00:07:26 +00:00
if (!is_dir($cache_path)) { // 创建cache目录
2022-01-12 18:48:08 +00:00
mkdir($cache_path, 0777, true);
}
2022-01-30 00:07:26 +00:00
if (!isAnimatedGif($old_img_path)) { // 仅针对非gif创建图片缩略图
2022-01-12 18:48:08 +00:00
$new_imgName = APP_ROOT . $config['path'] . 'thumbnails/' . date('Y_m_d') . '_' . $imgName; // 缩略图缓存的绝对路径
2022-01-30 00:07:26 +00:00
Thumb::out($old_img_path, $new_imgName, 258, 258); // 保存缩略图
2022-01-12 18:48:08 +00:00
}
2021-11-09 03:43:23 +00:00
}
2022-01-27 09:25:46 +00:00
/**
* 根据请求网址路径返回缩略图网址
* @param $url string 图片链接
* @return string
*/
2022-01-01 07:40:23 +00:00
function return_thumbnail_images($url)
2021-11-09 03:43:23 +00:00
{
2022-01-12 18:48:08 +00:00
global $config;
$cache_image_file = str_replace($config['imgurl'], '', $url);
2021-11-09 03:43:23 +00:00
2022-01-30 00:07:26 +00:00
if (isAnimatedGif(APP_ROOT . $cache_image_file)) { // 仅读取非gif的缩略图
return $url; // 如果是gif则直接返回url
2022-01-12 18:48:08 +00:00
} else {
2022-01-30 00:07:26 +00:00
$cache_image_file = str_replace($config['path'], '', $cache_image_file); // 将网址中的/i/去除
$cache_image_file = str_replace('/', '_', $cache_image_file); // 将文件的/转换为_
$isFile = APP_ROOT . $config['path'] . 'thumbnails/' . $cache_image_file; // 缓存文件的绝对路径
if (file_exists($isFile)) { // 缓存文件是否存在
2022-01-12 18:48:08 +00:00
return $config['imgurl'] . $config['path'] . 'thumbnails/' . $cache_image_file; // 存在则返回缓存文件
} else {
2022-01-30 00:07:26 +00:00
return $url; // 不存在直接返回url
2022-01-12 18:48:08 +00:00
}
}
2021-11-09 03:43:23 +00:00
}
2022-01-27 09:25:46 +00:00
/**
* 在线输出缩略图
* @param $imgUrl string 图片链接
* @return string 缩略图链接
*/
2022-01-04 09:09:56 +00:00
function get_online_thumbnail($imgUrl)
{
2022-01-12 18:48:08 +00:00
global $config;
if ($config['thumbnail']) {
2022-05-03 05:00:40 +00:00
$imgUrl = str_replace($config['domain'], '', $imgUrl);
2022-01-30 00:07:26 +00:00
return $config['domain'] . '/application/thumb.php?img=' . $imgUrl;
2022-01-12 18:48:08 +00:00
} else {
return $imgUrl;
}
2022-01-04 09:09:56 +00:00
}
/**
* 用户浏览广场的时候生成缩略图,由此解决上传生成缩略图时服务器超时响应
2022-01-12 18:48:08 +00:00
* @param $imgUrl string 源图片网址
2022-01-04 09:09:56 +00:00
* @return string 缩略图地址
*/
function creat_thumbnail_by_list($imgUrl)
{
2022-01-12 18:48:08 +00:00
global $config;
2022-01-04 09:09:56 +00:00
2022-01-27 09:25:46 +00:00
ini_set('max_execution_time', '60'); // 脚本运行的时间以秒为单位0不限制
2022-01-12 18:48:08 +00:00
// 关闭缩略图
if ($config['thumbnail'] === 0) {
return $imgUrl;
}
// 实时生成
if ($config['thumbnail'] === 1) {
return get_online_thumbnail($imgUrl);
}
2022-01-04 09:09:56 +00:00
2022-01-12 18:48:08 +00:00
// 将网址图片转换为相对路径
2022-05-03 05:00:40 +00:00
$pathName = str_replace($config['domain'], '', $imgUrl);
2022-01-04 09:09:56 +00:00
2022-01-12 18:48:08 +00:00
// 图片绝对路径
$abPathName = APP_ROOT . $pathName;
2022-01-04 09:09:56 +00:00
2022-05-03 05:00:40 +00:00
// 将网址中的/i/去除
$pathName = str_replace($config['path'], '', $pathName);
2022-01-04 09:09:56 +00:00
2022-05-03 05:00:40 +00:00
// 将文件的/转换为_
$imgName = str_replace('/', '_', $pathName);
2022-01-04 09:09:56 +00:00
2022-05-03 05:00:40 +00:00
// 缓存文件是否存在
if (file_exists(APP_ROOT . $config['path'] . 'thumbnails/' . $imgName)) {
// 存在则返回缓存文件
return $config['domain'] . $config['path'] . 'thumbnails/' . $imgName;
} else {
2022-01-04 09:09:56 +00:00
2022-05-03 05:00:40 +00:00
// 如果图像是gif则直接返回网址
if (isAnimatedGif($abPathName)) {
return $imgUrl;
}
2022-01-04 09:09:56 +00:00
2022-05-03 05:00:40 +00:00
// 如果是webp动图则直接返回网址
if (isWebpAnimated($abPathName)) {
return $imgUrl;
}
2022-05-03 05:00:40 +00:00
// 过滤非指定格式
if (!in_array(pathinfo(basename($abPathName), PATHINFO_EXTENSION), array('png', 'gif', 'jpeg', 'jpg', 'webp', 'bmp'))) {
return $imgUrl;
}
2022-01-04 09:09:56 +00:00
2022-05-03 05:00:40 +00:00
// 创建缓存文件并输出文件链接
require_once __DIR__ . '/class.thumb.php';
2022-01-04 09:09:56 +00:00
2022-05-03 05:00:40 +00:00
// thumbnails目录的绝对路径
$cache_path = APP_ROOT . $config['path'] . 'thumbnails/';
2022-01-04 09:09:56 +00:00
2022-05-03 05:00:40 +00:00
// 创建cache目录
if (!is_dir($cache_path)) {
mkdir($cache_path, 0777, true);
}
2022-01-04 11:04:51 +00:00
2022-05-03 05:00:40 +00:00
// 缩略图缓存的绝对路径
// $imgName 是不带/i/的相对路径
2022-01-04 09:09:56 +00:00
2022-05-03 05:00:40 +00:00
$new_imgName = $cache_path . $imgName;
2022-01-04 09:09:56 +00:00
2022-05-03 05:00:40 +00:00
// 创建并保存缩略图
Thumb::out($abPathName, $new_imgName, 258, 258);
// 输出缩略图
return $new_imgName;
2022-01-12 18:48:08 +00:00
}
2022-01-04 09:09:56 +00:00
}
2022-01-27 09:25:46 +00:00
/**
* 获取当前页面完整URL地址
2021-11-09 03:43:23 +00:00
* https://www.php.cn/php-weizijiaocheng-28181.html
2022-01-27 09:25:46 +00:00
* @param null $search string 返回指定搜索文字之前的内容(不含搜索文字)
* @return false|string 返回读取网址
2021-11-09 03:43:23 +00:00
*/
function get_whole_url($search = null)
{
2022-01-12 18:48:08 +00:00
$sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';
2022-01-27 09:25:46 +00:00
$php_self = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : $_SERVER['SCRIPT_NAME'];
2022-01-12 18:48:08 +00:00
$path_info = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';
$relate_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $php_self . (isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : $path_info);
$whole_domain = $sys_protocal . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '') . $relate_url;
if ($search) {
// 返回指定符号之前
return substr($whole_domain, 0, strrpos($whole_domain, $search));
}
2022-04-13 10:15:38 +00:00
return $whole_domain;
2021-11-09 03:43:23 +00:00
}
2022-01-27 09:25:46 +00:00
/**
* 配置写入
* @param $filename string 要存储的源文件名称
* @param $values array 获取到的数组
* @param string $var 源文件的数组名称
* @param bool $format 不知道啥作用
* @return bool
*/
2021-11-09 03:43:23 +00:00
function cache_write($filename, $values, $var = 'config', $format = false)
{
2022-01-12 18:48:08 +00:00
$cachefile = $filename;
$cachetext = "<?php\r\n" . '$' . $var . '=' . arrayeval($values, $format) . ";";
return writefile($cachefile, $cachetext);
2021-11-09 03:43:23 +00:00
}
2022-01-27 09:25:46 +00:00
/**
* 数组转换成字串
* @param array $array 要转换的数组
* @param bool $format 不知道啥作用
* @param int $level 层级
* @return string
*/
2021-11-09 03:43:23 +00:00
function arrayeval($array, $format = false, $level = 0)
{
2022-01-12 18:48:08 +00:00
$space = $line = '';
if (!$format) {
for ($i = 0; $i <= $level; $i++) {
$space .= "\t";
}
$line = "\n";
}
$evaluate = 'Array' . $line . $space . '(' . $line;
$comma = $space;
foreach ($array as $key => $val) {
$key = is_string($key) ? '\'' . addcslashes($key, '\'\\') . '\'' : $key;
$val = !is_array($val) && (!preg_match('/^\-?\d+$/', $val) || strlen($val) > 12) ? '\'' . addcslashes($val, '\'\\') . '\'' : $val;
if (is_array($val)) {
$evaluate .= $comma . $key . '=>' . arrayeval($val, $format, $level + 1);
} else {
$evaluate .= $comma . $key . '=>' . $val;
}
$comma = ',' . $line . $space;
}
$evaluate .= $line . $space . ')';
return $evaluate;
}
2022-01-27 09:25:46 +00:00
/**
* 配置写入文件
* @param $filename string 要写入的文件名
* @param $writetext array 要写入的文字
* @param string $openmod 写文件模式
* @return bool
*/
2021-11-09 03:43:23 +00:00
function writefile($filename, $writetext, $openmod = 'w')
{
2022-01-12 18:48:08 +00:00
if (false !== $fp = fopen($filename, $openmod)) {
flock($fp, 2);
fwrite($fp, $writetext);
fclose($fp);
return true;
} else {
return false;
}
2021-11-09 03:43:23 +00:00
}
2022-01-19 17:55:20 +00:00
2022-01-27 09:25:46 +00:00
/**
2022-01-19 17:55:20 +00:00
* 获得用户的真实IP地址
2022-01-27 09:25:46 +00:00
* 来源ecshop
* @return mixed|string string
2022-01-19 17:55:20 +00:00
*/
function real_ip()
{
static $realip = NULL;
if ($realip !== NULL) {
return $realip;
}
if (isset($_SERVER)) {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
/* 取X-Forwarded-For中第一个非unknown的有效IP字符串 */
foreach ($arr as $ip) {
$ip = trim($ip);
if ($ip != 'unknown') {
$realip = $ip;
break;
}
}
} elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
$realip = $_SERVER['HTTP_CLIENT_IP'];
} else {
if (isset($_SERVER['REMOTE_ADDR'])) {
$realip = $_SERVER['REMOTE_ADDR'];
} else {
$realip = '0.0.0.0';
}
}
} else {
if (getenv('HTTP_X_FORWARDED_FOR')) {
$realip = getenv('HTTP_X_FORWARDED_FOR');
} elseif (getenv('HTTP_CLIENT_IP')) {
$realip = getenv('HTTP_CLIENT_IP');
} else {
$realip = getenv('REMOTE_ADDR');
}
}
// 使用正则验证IP地址的有效性防止伪造IP地址进行SQL注入攻击
preg_match("/[\d\.]{7,15}/", $realip, $onlineip);
$realip = !empty($onlineip[0]) ? $onlineip[0] : '0.0.0.0';
return $realip;
}
2022-01-27 09:25:46 +00:00
/**
2022-01-19 17:55:20 +00:00
* IP黑白名单检测支持IP段检测
* @param string $ipNow 要检测的IP
* @param string|array $ipList 白名单IP或者黑名单IP
* @return boolean false|true true:白名单模式false:黑名单模式
2022-01-27 09:25:46 +00:00
* @return bool
2022-01-19 17:55:20 +00:00
*/
function checkIP($ipNow = null, $ipList = null, $model = false)
{
$ipNow = isset($ipNow) ?: real_ip();
// 将IP文本转换为数组
if (is_string($ipList)) {
$ipList = explode(",", $ipList);
} else {
echo 'IP名单错误';
}
$ipregexp = implode('|', str_replace(array('*', '.'), array('\d+', '\.'), $ipList));
$result = preg_match("/^(" . $ipregexp . ")$/", $ipNow);
// 白名单模式
if ($model) {
if (in_array($ipNow, $ipList)) {
return false;
}
}
// 黑名单模式
if ($result) {
return true;
}
}
2022-02-01 19:28:06 +00:00
/**
* 测试IP或者url是否可以ping通
* @param $host string ip或网址
* @param $port int 端口
* @param $timeout float 过期时间
* @return bool true|false
*/
function IP_URL_Ping($host, $port, $timeout)
{
$errno = 444;
$errstr = 'fSockOpen 错误';
$fP = fSockOpen($host, $port, $errno, $errstr, $timeout);
if (!$fP) {
return false;
}
return true;
}
2022-03-04 13:45:10 +00:00
/**
* 生成Token
* @param int $length Token长度
* @return string 返回Token
*/
function privateToken($length = 32)
{
$output = '';
for ($a = 0; $a < $length; $a++) {
$output .= chr(mt_rand(65, 122)); //生成php随机数
}
return md5($output);
}
/**
* 检查Token
* @param $token 要检查的Token
* code:201 访问成功但是服务端关闭API上传
* code:202 访问成功但是Token错误
*/
function check_api($token)
{
global $config;
global $tokenList;
if (!$config['apiStatus']) {
2022-03-07 04:34:04 +00:00
// 关闭API
2022-03-04 13:45:10 +00:00
$reJson = array(
"result" => 'failed',
'code' => 201,
'message' => 'API Closed',
);
exit(json_encode($reJson, JSON_UNESCAPED_UNICODE));
}
if (!in_array($tokenList[$token], $tokenList)) {
2022-03-07 04:34:04 +00:00
// Token 存在
2022-03-04 13:45:10 +00:00
$reJson = array(
"result" => 'failed',
'code' => 202,
'message' => 'Token Error',
);
exit(json_encode($reJson, JSON_UNESCAPED_UNICODE));
}
if ($tokenList[$token]['expired'] < time()) {
2022-03-07 04:34:04 +00:00
// Token 过期
2022-03-04 13:45:10 +00:00
$reJson = array(
"result" => 'failed',
'code' => 203,
'message' => 'Token Expired',
);
exit(json_encode($reJson, JSON_UNESCAPED_UNICODE));
}
}
/**
* 判断webp是否为动态图片
* @param $src 图像文件
* @return bool |
*/
function isWebpAnimated($src)
{
$webpContents = file_get_contents($src);
$where = strpos($webpContents, "ANMF");
if ($where !== FALSE) {
// animated
$isAnimated = true;
} else {
2022-03-16 07:18:32 +00:00
// not animated
2022-03-04 13:45:10 +00:00
$isAnimated = false;
}
return $isAnimated;
}
2022-03-16 07:18:32 +00:00
/**
2022-04-16 05:23:49 +00:00
* 根据URL判断是否本地局域网访问(PHP代码函数)
2022-03-16 07:18:32 +00:00
* https://blog.csdn.net/monxinmonxin0/article/details/44854383
* @param $url 要判断的网址
* @return bool |
*/
function is_local($url)
{
if (stristr($url, 'localhost') || stristr($url, '127.') || stristr($url, '192.')) {
return true;
}
2022-04-16 05:23:49 +00:00
return false;
2022-03-16 07:18:32 +00:00
}
2022-05-03 05:00:40 +00:00
/**
* 将图片域名转换为数组并随即输出
*/
function rand_imgurl($text = null)
{
global $config;
$url = isset($text) ? $text : $config['imgurl'];
$url = explode(',', $url);
return $url[array_rand($url, 1)];
}