This commit is contained in:
尖叫 2023-11-29 15:28:26 +08:00
parent 87f691d2e8
commit 7a545ea88f
4 changed files with 211 additions and 161 deletions

View File

@ -165,23 +165,13 @@ $this->params['breadcrumbs'][] = $this->title;
$json_de = json_decode($model->goodsHub->video_url, true);
$temp_arr = [];
foreach ($json_de as $key => $val) {
if($_SERVER['REMOTE_ADDR'] == '127.0.0.1'){
$val_model = filesize('D:/phpstudy_pro/WWW/cxgj/web' . $val);
}else{
$val_model = filesize($_SERVER["DOCUMENT_ROOT"] . $val);
}
$explode = explode('/', $val);
$end = end($explode);
//
$temp_arr[] = [
'name' => $end,
'url' => $val,
'size_cn' => $val_model,
];
}
$model->goodsHub->video_url = json_encode($temp_arr, JSON_UNESCAPED_UNICODE);
}

View File

@ -103,18 +103,11 @@ $this->params['breadcrumbs'][] = $this->title;
$temp_arr = [];
foreach ($json_de as $key => $val) {
if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') {
$val_model = filesize('D:/phpstudy_pro/WWW/cxgj/web' . $val);
} else {
$val_model = filesize($_SERVER["DOCUMENT_ROOT"] . $val);
}
$explode = explode('/', $val);
$end = end($explode);
//
$temp_arr[] = [
'name' => $end,
'url' => $val,
'size_cn' => $val_model,
];
}
$model->cover_pic = json_encode($temp_arr, JSON_UNESCAPED_UNICODE);

View File

@ -12,12 +12,15 @@
namespace app\modules\file\controllers;
use app\components\Oss;
use Yii;
use app\modules\file\components\Uploader;
use app\modules\file\components\UploadHelper;
use app\models\file\UploadFile;
use app\models\Model;
set_time_limit(0);
use Gumlet\ImageResize;
use Gumlet\ImageResizeException;
@ -365,8 +368,63 @@ class UploadController extends \app\controllers\Controller
}
}
//上传图片
public function actionImage($rfmt = 'default')
// //上传图片
// public function actionImage($rfmt = 'default')
// {
// if(!\Yii::$app->request->isPost){
// $data = [
// 'code' => 1,
// 'msg' => "Invalid Request"
// ];
// return $this->responseHandler($data);
// }
// $action = "uploadimage";
// $fileInfo = $this->uploadFile($action);
// if($rfmt == 'default'){
// if($fileInfo["state"] == "SUCCESS"){
// $data = [
// 'code' => 0,
// 'msg' => 'success',
// 'data' => [
// 'url' => $fileInfo['url'],
// 'extension' => $fileInfo["type"],
// 'size' => $fileInfo["size"],
// 'type' => $this->getFileType(trim($fileInfo['type'],"."))
// ]
// ];
// } else {
// $data = [
// 'code' => 1,
// 'msg' => $fileInfo["state"]
// ];
// }
// } else if($rfmt == 'wangeditor'){
// if($fileInfo["state"] == "SUCCESS"){
// $data = [
// 'errno' => 0,
// 'message' => 'success',
// 'data' => [
// 'url' => $fileInfo['url'],
// 'alt' => '',
// 'href' => '',
// 'extension' => $fileInfo["type"],
// 'size' => $fileInfo["size"],
// 'type' => $this->getFileType(trim($fileInfo['type'],"."))
// ]
// ];
// } else {
// $data = [
// 'errno' => 1,
// 'message' => $fileInfo["state"]
// ];
// }
// }
// return $this->responseHandler($data);
// }
//上传图片到OSS
public function actionImage()
{
if (!\Yii::$app->request->isPost) {
$data = [
@ -375,50 +433,55 @@ class UploadController extends \app\controllers\Controller
];
return $this->responseHandler($data);
}
$action = "uploadimage";
$fileInfo = $this->uploadFile($action);
if($rfmt == 'default'){
if($fileInfo["state"] == "SUCCESS"){
if (empty($_FILES['file']['name'])) {
$data = [
'code' => 1,
'msg' => "请选择要上传的文件"
];
return $this->responseHandler($data);
}
// 上传文件的目录
$upload_dir = "/web/uploads/1/";
if (!is_dir($upload_dir)) {
mkdir(\Yii::$app->basePath . '/web/upload/1', 0777, true);
}
$file = md5($_FILES['file']['name']);
// 上传文件的全名
$upload_file = \Yii::$app->basePath . '/web/upload/1/' . $file . '.png';
// 将上传的文件从临时目录移动到指定目录
if (!move_uploaded_file($_FILES['file']['tmp_name'], $upload_file)) {
$data = [
'code' => 1,
'msg' => "文件上传失败"
];
} else {
$oss = new Oss();
$file = '/web/upload/1/' . $file . '.png';
//上传文件目录
$oss_data = $oss->upload($upload_file, $file);
if ($oss == false) {
$data = [
'code' => 1,
'msg' => "文件上传失败"
];
} else {
$data = [
'code' => 0,
'msg' => 'success',
'data' => [
'url' => $fileInfo['url'],
'extension' => $fileInfo["type"],
'size' => $fileInfo["size"],
'type' => $this->getFileType(trim($fileInfo['type'],"."))
'url' => $oss_data,
]
];
} else {
$data = [
'code' => 1,
'msg' => $fileInfo["state"]
];
}
} else if($rfmt == 'wangeditor'){
if($fileInfo["state"] == "SUCCESS"){
$data = [
'errno' => 0,
'message' => 'success',
'data' => [
'url' => $fileInfo['url'],
'alt' => '',
'href' => '',
'extension' => $fileInfo["type"],
'size' => $fileInfo["size"],
'type' => $this->getFileType(trim($fileInfo['type'],"."))
]
];
} else {
$data = [
'errno' => 1,
'message' => $fileInfo["state"]
];
}
}
return $this->responseHandler($data);
}
//上传文件
public function actionFile($rfmt = 'default')
{
@ -509,7 +572,8 @@ class UploadController extends \app\controllers\Controller
* @TODO 扩展上传至第三方存储
* 文件上传
*/
private function uploadFile($action){
private function uploadFile($action)
{
//获取上传配置
$uploadConfig = $this->getUploadConfig($action);
$path = $uploadConfig["path"];
@ -651,7 +715,8 @@ class UploadController extends \app\controllers\Controller
/**
* 获取已经上传的文件列表
*/
private function getFileList($action){
private function getFileList($action)
{
//获取上传配置
$uploadConfig = $this->getUploadConfig($action);
$_path = $uploadConfig["path"];
@ -746,7 +811,8 @@ class UploadController extends \app\controllers\Controller
/**
* 获取上传路径前缀,及配置信息
*/
private function getUploadConfig($action){
private function getUploadConfig($action)
{
$path = UploadHelper::getUploadPath();
$config = $this->uploadConfig['uploadFile'];
@ -760,7 +826,8 @@ class UploadController extends \app\controllers\Controller
/**
* 抓取远程图片
*/
private function crawlerImage($action) {
private function crawlerImage($action)
{
set_time_limit(0);
//获取上传配置
$uploadConfig = $this->getUploadConfig($action);

View File

@ -109,7 +109,7 @@ $this->registerJsFile($layui_js_file, ['depends' => 'app\modules\admin\assets\Ap
<tr>
<th>名称</th>
<th>文件</th>
<th>大小</th>
<!-- <th>大小</th>-->
<th>状态</th>
<th style="width:188px">操作</th>
</tr>
@ -118,7 +118,7 @@ $this->registerJsFile($layui_js_file, ['depends' => 'app\modules\admin\assets\Ap
<tr v-for="(item,index) in filelist">
<td>{{item.name}}</td>
<td>{{item.url}}</td>
<td>{{item.size_cn}}</td>
<!-- <td>{{item.size_cn}}</td>-->
<td>
<template v-if="item.status == 0">
<span class="layui-badge layui-bg-gray">待上传</span>