<?php /** * 附件上传 * Created by PhpStorm. * User: mr.song * Date: 2016/7/22 * Time: 16:49 */ namespace Apicp\Controller\Attachment; use VcySDK\Service; use VcySDK\Attach; class UploadAttaController extends 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 ); $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); $this->_result = $result; return true; } }