12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Author: kane <chengjin005@163.com>
- // +----------------------------------------------------------------------
- namespace admin\user\controller;
- use cmf\controller\AdminBaseController;
- use cmf\lib\Upload;
- use think\Lang;
- /**
- * 附件上传控制器
- * Class Asset
- * @package app\asset\controller
- */
- class AssetController extends AdminBaseController
- {
- public function _initialize()
- {
- $adminId = cmf_get_current_admin_id();
- $userId = cmf_get_current_user_id();
- if (empty($adminId) && empty($userId)) {
- exit("非法上传!");
- }
- Lang::load(APP_PATH.'user/lang'.DS.$this->lang.DS.'admin_webuploader'.EXT);
- }
- /**
- * webuploader 上传
- */
- public function webuploader()
- {
- if ($this->request->isPost()) {
- $uploader = new Upload();
- $result = $uploader->upload();
- if ($result === false) {
- $this->adminError($uploader->getError());
- } else {
- $this->adminSuccess("上传成功!", '', $result);
- }
- } else {
- $uploadSetting = cmf_get_upload_setting();
- $arrFileTypes = [
- 'image' => ['title' => 'Image files', 'extensions' => $uploadSetting['file_types']['image']['extensions']],
- 'video' => ['title' => 'Video files', 'extensions' => $uploadSetting['file_types']['video']['extensions']],
- 'audio' => ['title' => 'Audio files', 'extensions' => $uploadSetting['file_types']['audio']['extensions']],
- 'file' => ['title' => 'Custom files', 'extensions' => $uploadSetting['file_types']['file']['extensions']]
- ];
- $arrData = $this->request->param();
- if (empty($arrData["filetype"])) {
- $arrData["filetype"] = "image";
- }
- $fileType = $arrData["filetype"];
- if (array_key_exists($arrData["filetype"], $arrFileTypes)) {
- $extensions = $uploadSetting['file_types'][$arrData["filetype"]]['extensions'];
- $fileTypeUploadMaxFileSize = $uploadSetting['file_types'][$fileType]['upload_max_filesize'];
- } else {
- $this->adminError('上传文件类型配置错误!');
- }
- $this->assign('filetype', $arrData["filetype"]);
- $this->assign('extensions', $extensions);
- $this->assign('upload_max_filesize', $fileTypeUploadMaxFileSize * 1024);
- $this->assign('upload_max_filesize_mb', intval($fileTypeUploadMaxFileSize / 1024));
- $maxFiles = intval($uploadSetting['max_files']);
- $maxFiles = empty($maxFiles) ? 20 : $maxFiles;
- $chunkSize = intval($uploadSetting['chunk_size']);
- $chunkSize = empty($chunkSize) ? 512 : $chunkSize;
- $this->assign('max_files', $arrData["multi"] ? $maxFiles : 1);
- $this->assign('chunk_size', $chunkSize); //// 单位KB
- $this->assign('multi', $arrData["multi"]);
- $this->assign('app', $arrData["app"]);
- return $this->fetch(":webuploader");
- }
- }
- }
|