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); $json_de = json_decode($model->goodsHub->video_url, true);
$temp_arr = []; $temp_arr = [];
foreach ($json_de as $key => $val) { 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); $explode = explode('/', $val);
$end = end($explode); $end = end($explode);
// //
$temp_arr[] = [ $temp_arr[] = [
'name' => $end, 'name' => $end,
'url' => $val, 'url' => $val,
'size_cn' => $val_model,
]; ];
} }
$model->goodsHub->video_url = json_encode($temp_arr, JSON_UNESCAPED_UNICODE); $model->goodsHub->video_url = json_encode($temp_arr, JSON_UNESCAPED_UNICODE);
} }

View File

@ -103,18 +103,11 @@ $this->params['breadcrumbs'][] = $this->title;
$temp_arr = []; $temp_arr = [];
foreach ($json_de as $key => $val) { 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); $explode = explode('/', $val);
$end = end($explode); $end = end($explode);
//
$temp_arr[] = [ $temp_arr[] = [
'name' => $end, 'name' => $end,
'url' => $val, 'url' => $val,
'size_cn' => $val_model,
]; ];
} }
$model->cover_pic = json_encode($temp_arr, JSON_UNESCAPED_UNICODE); $model->cover_pic = json_encode($temp_arr, JSON_UNESCAPED_UNICODE);

View File

@ -12,12 +12,15 @@
namespace app\modules\file\controllers; namespace app\modules\file\controllers;
use app\components\Oss;
use Yii; use Yii;
use app\modules\file\components\Uploader; use app\modules\file\components\Uploader;
use app\modules\file\components\UploadHelper; use app\modules\file\components\UploadHelper;
use app\models\file\UploadFile; use app\models\file\UploadFile;
use app\models\Model; use app\models\Model;
set_time_limit(0); set_time_limit(0);
use Gumlet\ImageResize; use Gumlet\ImageResize;
use Gumlet\ImageResizeException; use Gumlet\ImageResizeException;
@ -301,11 +304,11 @@ class UploadController extends \app\controllers\Controller
case 'uploadvideo': case 'uploadvideo':
/* 上传文件 */ /* 上传文件 */
case 'uploadfile': case 'uploadfile':
if(isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == "OPTIONS"){ if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == "OPTIONS") {
//判断实际发送的请求是否安全 //判断实际发送的请求是否安全
$result = ""; $result = "";
} else { } else {
if(Yii::$app->request->isPost && !empty($_FILES)){ if (Yii::$app->request->isPost && !empty($_FILES)) {
//上传 //上传
$currentFileInfo = $this->uploadFile($action); $currentFileInfo = $this->uploadFile($action);
$result = json_encode($currentFileInfo); $result = json_encode($currentFileInfo);
@ -317,7 +320,7 @@ class UploadController extends \app\controllers\Controller
/* 列出图片 */ /* 列出图片 */
case 'listimage': case 'listimage':
if(isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == "OPTIONS"){ if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == "OPTIONS") {
$result = ""; $result = "";
} else { } else {
//返回结果 //返回结果
@ -326,7 +329,7 @@ class UploadController extends \app\controllers\Controller
break; break;
/* 列出文件 */ /* 列出文件 */
case 'listfile': case 'listfile':
if(isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == "OPTIONS"){ if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == "OPTIONS") {
$result = ""; $result = "";
} else { } else {
//返回结果 //返回结果
@ -336,7 +339,7 @@ class UploadController extends \app\controllers\Controller
/* 抓取远程文件 */ /* 抓取远程文件 */
case 'catchimage': case 'catchimage':
if(isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == "OPTIONS"){ if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == "OPTIONS") {
$result = ""; $result = "";
} else { } else {
//返回结果 //返回结果
@ -346,7 +349,7 @@ class UploadController extends \app\controllers\Controller
default: default:
$result = json_encode(array( $result = json_encode(array(
'state'=> '请求地址出错' 'state' => '请求地址出错'
)); ));
break; break;
} }
@ -357,7 +360,7 @@ class UploadController extends \app\controllers\Controller
echo htmlspecialchars($_GET["callback"]) . '(' . $result . ')'; echo htmlspecialchars($_GET["callback"]) . '(' . $result . ')';
} else { } else {
echo json_encode(array( echo json_encode(array(
'state'=> 'callback参数不合法' 'state' => 'callback参数不合法'
)); ));
} }
} else { } else {
@ -365,64 +368,124 @@ 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){ if (!\Yii::$app->request->isPost) {
$data = [ $data = [
'code' => 1, 'code' => 1,
'msg' => "Invalid Request" 'msg' => "Invalid Request"
]; ];
return $this->responseHandler($data); return $this->responseHandler($data);
} }
$action = "uploadimage";
$fileInfo = $this->uploadFile($action); if (empty($_FILES['file']['name'])) {
if($rfmt == 'default'){ $data = [
if($fileInfo["state"] == "SUCCESS"){ '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 = [ $data = [
'code' => 0, 'code' => 0,
'msg' => 'success', 'msg' => 'success',
'data' => [ 'data' => [
'url' => $fileInfo['url'], 'url' => $oss_data,
'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); return $this->responseHandler($data);
} }
//上传文件 //上传文件
public function actionFile($rfmt = 'default') public function actionFile($rfmt = 'default')
{ {
if(!\Yii::$app->request->isPost){ if (!\Yii::$app->request->isPost) {
$data = [ $data = [
'code' => 1, 'code' => 1,
'msg' => "Invalid Request" 'msg' => "Invalid Request"
@ -431,8 +494,8 @@ class UploadController extends \app\controllers\Controller
} }
$action = "uploadfile"; $action = "uploadfile";
$fileInfo = $this->uploadFile($action); $fileInfo = $this->uploadFile($action);
if($rfmt == 'default'){ if ($rfmt == 'default') {
if($fileInfo["state"] == "SUCCESS"){ if ($fileInfo["state"] == "SUCCESS") {
$data = [ $data = [
'code' => 0, 'code' => 0,
'msg' => 'success', 'msg' => 'success',
@ -440,7 +503,7 @@ class UploadController extends \app\controllers\Controller
'url' => $fileInfo['url'], 'url' => $fileInfo['url'],
'extension' => $fileInfo["type"], 'extension' => $fileInfo["type"],
'size' => $fileInfo["size"], 'size' => $fileInfo["size"],
'type' => $this->getFileType(trim($fileInfo['type'],".")) 'type' => $this->getFileType(trim($fileInfo['type'], "."))
] ]
]; ];
} else { } else {
@ -449,8 +512,8 @@ class UploadController extends \app\controllers\Controller
'msg' => $fileInfo["state"] 'msg' => $fileInfo["state"]
]; ];
} }
} else if($rfmt == 'wangeditor'){ } else if ($rfmt == 'wangeditor') {
if($fileInfo["state"] == "SUCCESS"){ if ($fileInfo["state"] == "SUCCESS") {
$data = [ $data = [
'errno' => 0, 'errno' => 0,
'message' => 'success', 'message' => 'success',
@ -460,7 +523,7 @@ class UploadController extends \app\controllers\Controller
'href' => '', 'href' => '',
'extension' => $fileInfo["type"], 'extension' => $fileInfo["type"],
'size' => $fileInfo["size"], 'size' => $fileInfo["size"],
'type' => $this->getFileType(trim($fileInfo['type'],".")) 'type' => $this->getFileType(trim($fileInfo['type'], "."))
] ]
]; ];
} else { } else {
@ -476,7 +539,7 @@ class UploadController extends \app\controllers\Controller
//上传视频 //上传视频
public function actionVideoFile() public function actionVideoFile()
{ {
if(!\Yii::$app->request->isPost){ if (!\Yii::$app->request->isPost) {
$data = [ $data = [
'code' => 1, 'code' => 1,
'msg' => "Invalid Request" 'msg' => "Invalid Request"
@ -484,7 +547,7 @@ class UploadController extends \app\controllers\Controller
} }
$action = "uploadvideo"; $action = "uploadvideo";
$fileInfo = $this->uploadFile($action); $fileInfo = $this->uploadFile($action);
if($fileInfo["state"] == "SUCCESS"){ if ($fileInfo["state"] == "SUCCESS") {
$data = [ $data = [
'code' => 0, 'code' => 0,
'msg' => 'success', 'msg' => 'success',
@ -492,7 +555,7 @@ class UploadController extends \app\controllers\Controller
'url' => $fileInfo['url'], 'url' => $fileInfo['url'],
'extension' => $fileInfo["type"], 'extension' => $fileInfo["type"],
'size' => $fileInfo["size"], 'size' => $fileInfo["size"],
'type' => $this->getFileType(trim($fileInfo['type'],".")) 'type' => $this->getFileType(trim($fileInfo['type'], "."))
] ]
]; ];
} else { } else {
@ -509,7 +572,8 @@ class UploadController extends \app\controllers\Controller
* @TODO 扩展上传至第三方存储 * @TODO 扩展上传至第三方存储
* 文件上传 * 文件上传
*/ */
private function uploadFile($action){ private function uploadFile($action)
{
//获取上传配置 //获取上传配置
$uploadConfig = $this->getUploadConfig($action); $uploadConfig = $this->getUploadConfig($action);
$path = $uploadConfig["path"]; $path = $uploadConfig["path"];
@ -575,12 +639,12 @@ class UploadController extends \app\controllers\Controller
/* 返回数据 */ /* 返回数据 */
$fileInfo = $up->getFileInfo(); $fileInfo = $up->getFileInfo();
if($fileInfo["state"] == "SUCCESS"){ if ($fileInfo["state"] == "SUCCESS") {
$this->imageCompress($fileInfo); $this->imageCompress($fileInfo);
$model = new UploadFile(); $model = new UploadFile();
$model->user_id = Model::getUserId(); $model->user_id = Model::getUserId();
$model->file_url = $fileInfo["url"]; $model->file_url = $fileInfo["url"];
$model->extension = trim($fileInfo["type"],"."); $model->extension = trim($fileInfo["type"], ".");
$model->type = $this->getFileType($model->extension); $model->type = $this->getFileType($model->extension);
$model->size = $fileInfo["size"]; $model->size = $fileInfo["size"];
$model->group_id = \Yii::$app->request->get("group_id"); $model->group_id = \Yii::$app->request->get("group_id");
@ -592,18 +656,18 @@ class UploadController extends \app\controllers\Controller
private function imageCompress(&$fileInfo) private function imageCompress(&$fileInfo)
{ {
$filetype = $this->getFileType(trim($fileInfo["type"],".")); $filetype = $this->getFileType(trim($fileInfo["type"], "."));
if($filetype != "image") if ($filetype != "image")
return; return;
$imageCompressConfig = $this->getImageCompressConfig(); $imageCompressConfig = $this->getImageCompressConfig();
$filename = trim($fileInfo["url"],'/'); $filename = trim($fileInfo["url"], '/');
if($imageCompressConfig['imageCompressEnable'] && file_exists($filename)){ if ($imageCompressConfig['imageCompressEnable'] && file_exists($filename)) {
try{ try {
$gumletImagic = new ImageResize($filename); $gumletImagic = new ImageResize($filename);
$gumletImagic->resizeToLongSide($imageCompressConfig['imageCompressBorder']); $gumletImagic->resizeToLongSide($imageCompressConfig['imageCompressBorder']);
$gumletImagic->save($filename); $gumletImagic->save($filename);
clearstatcache(); clearstatcache();
} catch (ImageResizeException $ex){ } catch (ImageResizeException $ex) {
} }
} }
$fileInfo["size"] = filesize($filename); $fileInfo["size"] = filesize($filename);
@ -618,14 +682,14 @@ class UploadController extends \app\controllers\Controller
{ {
$config = []; $config = [];
$imageCompressEnable = \Yii::$app->request->get('imageCompressEnable'); $imageCompressEnable = \Yii::$app->request->get('imageCompressEnable');
if($imageCompressEnable !== null){ if ($imageCompressEnable !== null) {
$config['imageCompressEnable'] = $imageCompressEnable == 1 ? true : false; $config['imageCompressEnable'] = $imageCompressEnable == 1 ? true : false;
} else { } else {
$config['imageCompressEnable'] = $this->uploadConfig['uploadFile']['imageCompressEnable']; $config['imageCompressEnable'] = $this->uploadConfig['uploadFile']['imageCompressEnable'];
} }
$imageCompressBorder = \Yii::$app->request->get('imageCompressBorder'); $imageCompressBorder = \Yii::$app->request->get('imageCompressBorder');
if($imageCompressBorder !== null && is_numeric($imageCompressBorder)){ if ($imageCompressBorder !== null && is_numeric($imageCompressBorder)) {
$imageCompressBorder = (int)$imageCompressBorder; $imageCompressBorder = (int)$imageCompressBorder;
$config['imageCompressBorder'] = $imageCompressBorder; $config['imageCompressBorder'] = $imageCompressBorder;
} else { } else {
@ -651,7 +715,8 @@ class UploadController extends \app\controllers\Controller
/** /**
* 获取已经上传的文件列表 * 获取已经上传的文件列表
*/ */
private function getFileList($action){ private function getFileList($action)
{
//获取上传配置 //获取上传配置
$uploadConfig = $this->getUploadConfig($action); $uploadConfig = $this->getUploadConfig($action);
$_path = $uploadConfig["path"]; $_path = $uploadConfig["path"];
@ -661,7 +726,7 @@ class UploadController extends \app\controllers\Controller
switch ($action) { switch ($action) {
/* 列出文件 */ /* 列出文件 */
case 'listfile': case 'listfile':
$_config['fileManagerListPath'] = $_path .$_config['fileManagerListPath']; $_config['fileManagerListPath'] = $_path . $_config['fileManagerListPath'];
$allowFiles = $_config['fileManagerAllowFiles']; $allowFiles = $_config['fileManagerAllowFiles'];
$listSize = $_config['fileManagerListSize']; $listSize = $_config['fileManagerListSize'];
$path = $_config['fileManagerListPath']; $path = $_config['fileManagerListPath'];
@ -682,7 +747,7 @@ class UploadController extends \app\controllers\Controller
$end = $start + $size; $end = $start + $size;
/* 获取文件列表 */ /* 获取文件列表 */
$path = $_SERVER['DOCUMENT_ROOT'] . (substr($path, 0, 1) == "/" ? "":"/") . $path; $path = $_SERVER['DOCUMENT_ROOT'] . (substr($path, 0, 1) == "/" ? "" : "/") . $path;
$files = $this->getfiles($path, $allowFiles); $files = $this->getfiles($path, $allowFiles);
if (!count($files)) { if (!count($files)) {
return json_encode(array( return json_encode(array(
@ -695,7 +760,7 @@ class UploadController extends \app\controllers\Controller
/* 获取指定范围的列表 */ /* 获取指定范围的列表 */
$len = count($files); $len = count($files);
for ($i = min($end, $len) - 1, $list = array(); $i < $len && $i >= 0 && $i >= $start; $i--){ for ($i = min($end, $len) - 1, $list = array(); $i < $len && $i >= 0 && $i >= $start; $i--) {
$list[] = $files[$i]; $list[] = $files[$i];
} }
//倒序 //倒序
@ -723,7 +788,7 @@ class UploadController extends \app\controllers\Controller
private function getfiles($path, $allowFiles, &$files = array()) private function getfiles($path, $allowFiles, &$files = array())
{ {
if (!is_dir($path)) return null; if (!is_dir($path)) return null;
if(substr($path, strlen($path) - 1) != '/') $path .= '/'; if (substr($path, strlen($path) - 1) != '/') $path .= '/';
$handle = opendir($path); $handle = opendir($path);
while (false !== ($file = readdir($handle))) { while (false !== ($file = readdir($handle))) {
if ($file != '.' && $file != '..') { if ($file != '.' && $file != '..') {
@ -731,10 +796,10 @@ class UploadController extends \app\controllers\Controller
if (is_dir($path2)) { if (is_dir($path2)) {
$this->getfiles($path2, $allowFiles, $files); $this->getfiles($path2, $allowFiles, $files);
} else { } else {
if (preg_match("/\.(".$allowFiles.")$/i", $file)) { if (preg_match("/\.(" . $allowFiles . ")$/i", $file)) {
$files[] = array( $files[] = array(
'url'=> substr($path2, strlen($_SERVER['DOCUMENT_ROOT'])), 'url' => substr($path2, strlen($_SERVER['DOCUMENT_ROOT'])),
'mtime'=> filemtime($path2) 'mtime' => filemtime($path2)
); );
} }
} }
@ -746,7 +811,8 @@ class UploadController extends \app\controllers\Controller
/** /**
* 获取上传路径前缀,及配置信息 * 获取上传路径前缀,及配置信息
*/ */
private function getUploadConfig($action){ private function getUploadConfig($action)
{
$path = UploadHelper::getUploadPath(); $path = UploadHelper::getUploadPath();
$config = $this->uploadConfig['uploadFile']; $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); set_time_limit(0);
//获取上传配置 //获取上传配置
$uploadConfig = $this->getUploadConfig($action); $uploadConfig = $this->getUploadConfig($action);
@ -798,29 +865,29 @@ class UploadController extends \app\controllers\Controller
/* 返回抓取数据 */ /* 返回抓取数据 */
return json_encode(array( return json_encode(array(
'state'=> count($list) ? 'SUCCESS': 'ERROR', 'state' => count($list) ? 'SUCCESS' : 'ERROR',
'list'=> $list 'list' => $list
)); ));
} }
public function actionVideo() public function actionVideo()
{ {
set_time_limit (0); set_time_limit(0);
$params = \Yii::$app->request->post(); $params = \Yii::$app->request->post();
$tempDir = './temp/upload/video/chunks/'.date('Ymd',time()) . '/' . md5($params['name']); $tempDir = './temp/upload/video/chunks/' . date('Ymd', time()) . '/' . md5($params['name']);
if(!file_exists($tempDir)) if (!file_exists($tempDir))
$this->mk_dir($tempDir); $this->mk_dir($tempDir);
if(!isset($params['chunk'])){ if (!isset($params['chunk'])) {
$params['chunk'] = 0; $params['chunk'] = 0;
} }
if(!isset($params['chunks'])){ if (!isset($params['chunks'])) {
$params['chunks'] = 1; $params['chunks'] = 1;
} }
//获取上传配置 //获取上传配置
$action = 'uploadvideo'; $action = 'uploadvideo';
$uploadConfig = $this->getUploadConfig($action); $uploadConfig = $this->getUploadConfig($action);
$config = array( $config = array(
"pathFormat" => $tempDir . '/' .$params['chunk'], "pathFormat" => $tempDir . '/' . $params['chunk'],
"maxSize" => $uploadConfig['config']['videoMaxSize'], "maxSize" => $uploadConfig['config']['videoMaxSize'],
"allowFiles" => $uploadConfig['config']['videoAllowFiles'] "allowFiles" => $uploadConfig['config']['videoAllowFiles']
); );
@ -830,17 +897,17 @@ class UploadController extends \app\controllers\Controller
$fileInfo = $up->getFileInfo(); $fileInfo = $up->getFileInfo();
$chunk = strval($params['chunk']); $chunk = strval($params['chunk']);
$chunkCount = strval($params['chunks']); $chunkCount = strval($params['chunks']);
if($chunk + 1 == $chunkCount){ if ($chunk + 1 == $chunkCount) {
//合并 //合并
$targetDir = './upload/video/'.date('Ymd',time()). '/' . md5($params['name']); $targetDir = './upload/video/' . date('Ymd', time()) . '/' . md5($params['name']);
if(!file_exists($targetDir)) if (!file_exists($targetDir))
$this->mk_dir($targetDir); $this->mk_dir($targetDir);
$finalName = $targetDir . $fileInfo['type']; $finalName = $targetDir . $fileInfo['type'];
if(file_exists($finalName)) if (file_exists($finalName))
unlink($finalName); unlink($finalName);
$file = fopen($finalName, 'wb'); $file = fopen($finalName, 'wb');
for($index = 0; $index < $chunkCount; $index++){ for ($index = 0; $index < $chunkCount; $index++) {
$tmpFile = $tempDir . '/'. $index . $fileInfo['type']; $tmpFile = $tempDir . '/' . $index . $fileInfo['type'];
$chunkFile = fopen($tmpFile, 'rb'); $chunkFile = fopen($tmpFile, 'rb');
$content = fread($chunkFile, filesize($tmpFile)); $content = fread($chunkFile, filesize($tmpFile));
fclose($chunkFile); fclose($chunkFile);
@ -859,8 +926,8 @@ class UploadController extends \app\controllers\Controller
return $fileInfo; return $fileInfo;
} }
private function mk_dir($dir,$mode = 0777) private function mk_dir($dir, $mode = 0777)
{ {
return is_dir($dir) or $this->mk_dir(dirname($dir),$mode) and mkdir($dir,$mode); return is_dir($dir) or $this->mk_dir(dirname($dir), $mode) and mkdir($dir, $mode);
} }
} }

View File

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