UploadController.class.php
2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* 上传文档
* Created by PhpStorm.
* User: mr.song
* Date: 2016/7/22
* Time: 16:49
*/
namespace Apicp\Controller\att;
use Common\Common\Vhall;
use VcySDK\Attach;
use VcySDK\Service;
class UploadController extends \Apicp\Controller\AbstractController
{
public function Index()
{
/*
* 文件类型
* 99=普通文件(最大5M),
* 1=图片(2M),
* 2=音频(2M),
* 3=视频(10M),
* 总文件大小最大30M,
* 支持类型 (xls,xlsx,jpg,jpeg,png,bmp,gif,mp3,amr,avi,mp4) (必填)
*/
$types = array(
Attach::TYPE_AUDIO,
Attach::TYPE_IMG,
Attach::TYPE_NORMAL,
Attach::TYPE_VIDEO
);
$liveId = I('post.liveId');
$atMediatype = I('post.atMediatype', 0, 'intval');
// 2018-03-22 14:42:37 员圈的应用标示符只有 yuanquan 这里不用接前端传的值 现在出现有些地方前端传的不对 导致报错
// $plIdentifier = I('post._identifier', '', 'trim');
$res_auth = I('post.res_auth', '', 'trim');
// 检查参数
if (!in_array($atMediatype, $types) || empty($_FILES)) {
$this->_set_error('_ERR_PARAMS_UNALLOWED');
return false;
}
$img_type = ['jpeg', 'jpg', 'png', 'bmp'];
// 获取文件后缀
$file_extension = end(explode('.', $_FILES['file']['name']));
if (in_array($file_extension, $img_type)) {
$atMediatype = Attach::TYPE_IMG;
}
if ($_FILES['file']['size'] == 0) {
E('_ERR_UPLOAD_FILE_IS_EMPTY');
}
$params = [
'plIdentifier' => APP_IDENTIFIER,
'atMediatype' => $atMediatype,
// 插入水印
'atInsertWaterMark' => cfg('FILE_UPLOAD_WATERMARK', null, true) ? Attach::INSERT_WATERMARK_TRUE : Attach::INSERT_WATERMARK_FALSE,
];
// 获取资源鉴权配置
if (!empty($res_auth)) {
$config = getResAuthConfig($res_auth);
// 合并资源鉴权参数
if (!empty($config)) {
$params = array_merge($params, $config);
}
}
$attach = new Attach(Service::instance());
$result = $attach->upload($params, $_FILES);
//如果是直播
if($liveId){
$res = Vhall::instance()->fileUpload(['liveId' => $liveId, 'atId' => $result['atId']]);
if(!empty($result['data'])){
$result = $res;
}
}
$this->_result = $result;
return true;
}
}