UploadAttaController.class.php
2.93 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* 附件上传
* Created by PhpStorm.
* User: mr.song
* Date: 2016/7/22
* Time: 16:49
*/
namespace Apicp\Controller\Attachment;
use Common\Common\Constant;
use VcySDK\Service;
use VcySDK\Attach;
class UploadAttaController extends AbstractController
{
/**
* UploadAtta
*
* @author heyuelong
* @desc 文件上传接口
*
* @param String atMediatype 附件类型
*
* @return array
*/
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
);
$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;
}
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);
$data = [
'title' => $this->dealPrefix($result['atFilename']),
'source_type' => Constant::SOURCE_TYPE_FILE,
'source_status' => Constant::SOURCE_STATUS_CONVERT,
'at_id' => $result['atId'],
'at_type' => Constant::ATTACH_TYPE_FILE,
'at_url' => $result['atAttachment'],
'at_name' => $result['atFilename'],
];
$source_id = $this->saveAtt($data);
$this->_result = [
'source_id' => $source_id
];
return true;
}
//去除标题末尾后缀
public function dealPrefix($title)
{
$deal_title = explode('.', $title);
array_pop($a);
$title=implode('.',$deal_title);
return $title;
}
}