190 lines
7.5 KiB
PHP
Executable File
190 lines
7.5 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: lock
|
|
* Date: 2021/7/30
|
|
* Time: 7:45 AM
|
|
*/
|
|
|
|
namespace app\index\controller;
|
|
|
|
|
|
use app\common\classLibrary\ClWechat;
|
|
use think\Request;
|
|
|
|
class Upload extends Common
|
|
{
|
|
/**
|
|
* upload
|
|
* @return \think\response\Json
|
|
*/
|
|
public function upload()
|
|
{
|
|
if(self::$result[self::$error_code_name] == 0)
|
|
{
|
|
$files = request()->file('file');
|
|
// 移动到框架应用根目录/public/uploads/ 目录下
|
|
$info = $files->rule('sha1')->validate(['size'=>10485760,'ext'=>'jpg,png,jpeg,mp4,doc,docx,xls,xlsx,ppt,pptx,pdf'])->move(ROOT_PATH . 'public' . DS . 'upload');
|
|
if($info){
|
|
$extension = $info->getExtension();
|
|
$saveName = $info->getSaveName();
|
|
$filename = $info->getFilename();
|
|
$fileAddress = $_SERVER['DOCUMENT_ROOT'].DS .'upload'. DS .$saveName;
|
|
self::$result['code'] = 0;
|
|
self::$result['data'] = array(
|
|
'src' => DS .'upload'. DS .$saveName
|
|
);
|
|
$info = $info->getInfo();
|
|
$data = array(
|
|
'file' => new \CURLFile(realpath($fileAddress)),
|
|
'access_token' => $this->createAccessToken(),
|
|
'debug' => 1
|
|
);
|
|
$url = config('api_domain').'/upload/upload';
|
|
$result = ClWechat::send_pic($url,$data);
|
|
$json_arr = json_decode($result,true);
|
|
if (array_key_exists('error_code',$json_arr))
|
|
{
|
|
if ($json_arr['error_code'] == 0)
|
|
{
|
|
unlink($fileAddress);
|
|
}
|
|
}
|
|
self::$result = $json_arr;
|
|
}else{
|
|
$error_msg = $files->getError();
|
|
self::$result['code'] = 10002;
|
|
self::$result['msg'] = $error_msg;
|
|
}
|
|
}
|
|
return json(self::$result);
|
|
}
|
|
|
|
/**
|
|
* upload
|
|
* @return \think\response\Json
|
|
*/
|
|
public function editUpload()
|
|
{
|
|
if(self::$result[self::$error_code_name] == 0)
|
|
{
|
|
$files = request()->file('file');
|
|
// 移动到框架应用根目录/public/uploads/ 目录下
|
|
$info = $files->rule('sha1')->validate(['size'=>10485760,'ext'=>'jpg,png,jpeg,mp4,doc,docx,xls,xlsx,ppt,pptx,pdf'])->move(ROOT_PATH . 'public' . DS . 'upload');
|
|
if($info){
|
|
$extension = $info->getExtension();
|
|
$saveName = $info->getSaveName();
|
|
$filename = $info->getFilename();
|
|
$fileAddress = $_SERVER['DOCUMENT_ROOT'].DS .'upload'. DS .$saveName;
|
|
self::$result['code'] = 0;
|
|
self::$result['data'] = array(
|
|
'src' => DS .'upload'. DS .$saveName
|
|
);
|
|
$info = $info->getInfo();
|
|
$data = array(
|
|
'file' => new \CURLFile(realpath($fileAddress)),
|
|
'access_token' => $this->createAccessToken(),
|
|
'debug' => 1
|
|
);
|
|
$url = config('api_domain').'/upload/editUpload';
|
|
$result = ClWechat::send_pic($url,$data);
|
|
$json_arr = json_decode($result,true);
|
|
if (array_key_exists('error_code',$json_arr))
|
|
{
|
|
if ($json_arr['error_code'] == 0)
|
|
{
|
|
$json_arr['data']['src'] = $json_arr['data']['src'];
|
|
unlink($fileAddress);
|
|
}
|
|
}
|
|
self::$result = $json_arr;
|
|
}else{
|
|
$error_msg = $files->getError();
|
|
self::$result['code'] = 10002;
|
|
self::$result['msg'] = $error_msg;
|
|
}
|
|
}
|
|
return json(self::$result);
|
|
}
|
|
|
|
/**
|
|
* ueditUpload
|
|
* @return \think\response\Json
|
|
*/
|
|
public function ueditUpload()
|
|
{
|
|
if(self::$result[self::$error_code_name] == 0)
|
|
{
|
|
$action = Request::instance()->get('action');
|
|
if ($action == 'config')
|
|
{
|
|
$config_arr = array(
|
|
'imageActionName' => 'uploadimage',
|
|
'imageFieldName' => 'upfile',
|
|
'imageMaxSize' => '2048000',
|
|
'imageAllowFiles' => [".png",".jpg",".jpeg",".gif",".bmp"],
|
|
'imageCompressEnable' => true,
|
|
'imageCompressBorder' => 1600,
|
|
'imageInsertAlign' => 'none',
|
|
'imageUrlPrefix' => '',
|
|
'imagePathFormat' => '\/ueditor\/php\/upload\/image\/{yyyy}{mm}{dd}\/{time}{rand:6}',
|
|
'videoActionName' => 'uploadvideo',
|
|
'videoFieldName' => 'upfile',
|
|
'videoPathFormat' => '\/ueditor\/php\/upload\/video\/{yyyy}{mm}{dd}\/{time}{rand:6}',
|
|
'videoUrlPrefix' => '',
|
|
'videoMaxSize' => 102400000,
|
|
'videoAllowFiles' => [".flv",".swf",".mkv",".avi",".rm",".rmvb",".mpeg",".mpg",".ogg",".ogv",".mov",".wmv",".mp4",".webm",".mp3",".wav",".mid"]
|
|
);
|
|
self::$result = $config_arr;
|
|
}elseif($action == 'uploadimage'){
|
|
$files = request()->file('upfile');
|
|
// 移动到框架应用根目录/public/uploads/ 目录下
|
|
$info = $files->rule('sha1')->validate(['size'=>10485760000,'ext'=>'jpg,png,jpeg,mp4,doc,docx,xls,xlsx,ppt,pptx,pdf'])->move(ROOT_PATH . 'public' . DS . 'upload');
|
|
if($info){
|
|
$extension = $info->getExtension();
|
|
$saveName = $info->getSaveName();
|
|
$filename = $info->getFilename();
|
|
$fileAddress = $_SERVER['DOCUMENT_ROOT'].DS .'upload'. DS .$saveName;
|
|
self::$result['code'] = 0;
|
|
self::$result['data'] = array(
|
|
'src' => DS .'upload'. DS .$saveName
|
|
);
|
|
$info = $info->getInfo();
|
|
|
|
$data = array(
|
|
'file' => new \CURLFile(realpath($fileAddress)),
|
|
'access_token' => $this->createAccessToken(),
|
|
'debug' => 1
|
|
);
|
|
$url = config('api_domain').'/upload/editUpload';
|
|
$result = ClWechat::send_pic($url,$data);
|
|
$json_arr = json_decode($result,true);
|
|
if (array_key_exists('error_code',$json_arr))
|
|
{
|
|
if ($json_arr['error_code'] == 0)
|
|
{
|
|
$json_arr['state'] = 'SUCCESS';
|
|
$json_arr['url'] = $json_arr['data']['src'];
|
|
$json_arr['title'] = $saveName;
|
|
$json_arr['original'] = $filename;
|
|
$json_arr['type'] = $extension;
|
|
$json_arr['size'] = 0;
|
|
$json_arr['data']['src'] = config('api_domain').$json_arr['data']['src'];
|
|
unlink($fileAddress);
|
|
}
|
|
}
|
|
self::$result = $json_arr;
|
|
}else{
|
|
$error_msg = $files->getError();
|
|
self::$result['code'] = 10002;
|
|
self::$result['msg'] = $error_msg;
|
|
}
|
|
}
|
|
}
|
|
return json(self::$result);
|
|
}
|
|
|
|
|
|
|
|
|
|
} |