Browse Source

创建后台逻辑层logic,创建file的逻辑文件FileManager.php,开发根据文件拓展名判断文件类型方法

wechat_public_accounts
linyaostalker 5 years ago
parent
commit
420d3e959d
  1. 11
      backend/config/main.php
  2. 44
      backend/logic/file/FileManager.php
  3. 7
      common/models/ars/TemFile.php

11
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,
];

44
backend/logic/file/FileManager.php

@ -0,0 +1,44 @@
<?php
namespace backend\logic\file;
use common\models\ars\TemFile;
class FileManager
{
public static $extension = [
TemFile::TYPE_IMAGE => ['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;
}
}

7
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}
*/

Loading…
Cancel
Save