From 420d3e959db4c9f5c99306486d32f40c004bddcf Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Thu, 21 Nov 2019 15:02:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E5=90=8E=E5=8F=B0=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=B1=82logic,=E5=88=9B=E5=BB=BAfile=E7=9A=84?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E6=96=87=E4=BB=B6FileManager.php,=E5=BC=80?= =?UTF-8?q?=E5=8F=91=E6=A0=B9=E6=8D=AE=E6=96=87=E4=BB=B6=E6=8B=93=E5=B1=95?= =?UTF-8?q?=E5=90=8D=E5=88=A4=E6=96=AD=E6=96=87=E4=BB=B6=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/config/main.php | 11 ++++++++ backend/logic/file/FileManager.php | 44 ++++++++++++++++++++++++++++++ common/models/ars/TemFile.php | 7 +++++ 3 files changed, 62 insertions(+) create mode 100644 backend/logic/file/FileManager.php diff --git a/backend/config/main.php b/backend/config/main.php index ec8c2c0..81c6961 100644 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -34,6 +34,16 @@ return [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning'], ], + [ + 'class' => 'yii\log\FileTarget', + 'levels' => ['info', 'error'], + 'categories' => ['imagetest'], + 'logFile' => '@app/runtime/logs/imagetest.log', + 'logVars' => [], + 'exportInterval' => 1, + 'prefix' => function ($message) { + } + ], ], ], 'errorHandler' => [ @@ -45,6 +55,7 @@ return [ 'rules' => [ ], ], + 'file' => ['class' => 'backend\logic\file\FileManager'], ], 'params' => $params, ]; diff --git a/backend/logic/file/FileManager.php b/backend/logic/file/FileManager.php new file mode 100644 index 0000000..cd65a41 --- /dev/null +++ b/backend/logic/file/FileManager.php @@ -0,0 +1,44 @@ + ['jpg', 'png', 'jpeg'], + TemFile::TYPE_VIDEO => ['mp4'], + TemFile::TYPE_EXCEL => [], + TemFile::TYPE_WORD => ['docx'], + TemFile::TYPE_TXT => ['txt'], + ]; + + /** + * @param $array + * @param $value + * @param int $key + * @return int + * 查看$extension数组中是否存在文件类型,不存在则返回-1 + */ + public function searchKey($array,$value, $key=-1){ + foreach($array as $k=>$row){ + if(!is_array($row)){ + if($row == $value){ + if($key != -1) { + return $key; + }else{ + return -1; + } + } + }else{ + $r = self::searchKey($row,$value, $k); + if($r != -1){ + return $r; + } + } + } + return -1; + } +} \ No newline at end of file diff --git a/common/models/ars/TemFile.php b/common/models/ars/TemFile.php index 52c228d..3123d8a 100644 --- a/common/models/ars/TemFile.php +++ b/common/models/ars/TemFile.php @@ -19,6 +19,13 @@ use yii\behaviors\TimestampBehavior; */ class TemFile extends \yii\db\ActiveRecord { + //类型type + const TYPE_IMAGE = 1;//图片 + const TYPE_VIDEO = 2;//影视 + const TYPE_EXCEL = 3;//excel表单 + const TYPE_WORD = 4;//word文本 + const TYPE_TXT = 5;//txt文本 + /** * {@inheritdoc} */