| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- /**
- * 文件上传模块
- * @author wesmiler
- */
- namespace app\api\controller;
- use app\admin\model\CarModel;
- use app\weixin\model\Commands;
- use app\weixin\model\FileLogs;
- use app\weixin\model\Member;
- use app\weixin\model\Storage;
- use app\weixin\model\Wechat;
- use app\weixin\service\PRedis;
- use cmf\controller\HomeBaseController;
- class StorageController extends HomeBaseController
- {
- /**
- * 图片上传
- */
- public function upload(){
- $file = request()->file('image');
- $scene = request()->get('scene','image');
- $water = request()->get('water',0);
- $fileData = Storage::uploadImg($file, $scene, $water);
- showJson(1005, 3002, $fileData);
- }
- /**
- * 图片上传
- */
- public function thumb(){
- $file = request()->file('image');
- $scene = request()->get('scene','image');
- $fileData = Storage::uploadImg($file, $scene);
- showJson(1005, 3002, $fileData);
- }
- /**
- * 认证图片上传
- */
- public function auth(){
- $file = request()->file('image');
- $scene = request()->get('scene','auth');
- $water = request()->get('water',1);
- $fileData = Storage::uploadImg($file, $scene, false);
- $siteInfo = cmf_get_site_info();
- $waterTxt = isset($siteInfo['water_txt']) ? trim($siteInfo['water_txt']) : '此证件仅限于拾光单身平台使用';
- if($waterTxt && $water){
- $img = isset($fileData['file']) ? $fileData['file'] : '';
- $img = Storage::imageWater($img, $waterTxt);
- $fileData['file'] = $img;
- $fileData['preview'] = cmf_get_image_preview_url($img);
- }
- showJson(1005, 3002, $fileData);
- }
- /**
- * 图片压缩
- * @return string
- */
- public function imgThumb(){
- $file = input('url');
- //PRedis::set('test:file1', $file, 600);
- if($file){
- header("Content-Type:image/jpeg");
- $type = input('t', 1);
- $params = [
- 'width'=> input('w', 1500),
- 'height'=> input('h', 1500),
- ];
- $strs = explode("/upload/", $file);
- $filename = isset($strs[1])? $strs[1] : '';
- //PRedis::set('test:file', $filename, 600);
- if($filename){
- $baseName = basename($filename);
- $cacheKey = 'files:thumb:'.substr($baseName,0,6).'_'.md5($filename).'_'.$params['width'].'_'.$params['height'].'_'.$type;
- $fileContent = PRedis::get($cacheKey);
- if($fileContent){
- echo $fileContent;
- exit;
- }
- if(file_exists('upload/'.$filename)){
- $file = Storage::imageThumb($filename, $type, $params);
- if(file_exists('upload/'.$file)){
- $fileContent = file_get_contents('upload/'.$file);
- PRedis::set($cacheKey, $fileContent, 6*3600);
- echo $fileContent;
- exit;
- }
- }
- }else{
- $cacheKey = 'files:thumb:'.md5($file);
- $fileContent = PRedis::get($cacheKey);
- if($fileContent){
- echo $fileContent;
- exit;
- }
- $fileContent = file_get_contents($file);
- PRedis::set($cacheKey, $fileContent, 6*3600);
- echo $fileContent;
- exit;
- }
- }
- header("Content-Type:image/png");
- echo file_get_contents('themes/default/weixin/public/assets/img/no-pic.png');
- exit;
- }
- }
- ?>
|