12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace app\common\controller;
- use think\facade\Request;
- use lemo\helper\DataHelper;
- class Upfile
- {
-
- protected $uploadValidate = [
- 'image' => 'filesize:102400|fileExt:jpg,png,gif,jpeg,rar,zip,avi,mp4,rmvb,3gp,flv,mp3,txt,doc,xls,ppt,pdf,xls,docx,xlsx,doc,wmv'
- ];
- protected $imageValidate = [
- 'image' => 'filesize:10240|fileExt:jpg,png,gif,jpeg,bmp,svg,wmv'
- ];
- protected $videoValidate = [
- 'file' => 'filesize:10240|avi,rmvb,3gp,flv,mp4,wmv'
- ];
- protected $voiceValidate = [
- 'file' => 'filesize:2048|mp3,wma,wav,amr,wmv'
- ];
- public function initialize()
- {
- $fileExt = getConfigByCode('upload_file_type');
- $filemax = getConfigByCode('upload_file_max') * 1024;
- $this->uploadValidate = ['image' =>
- 'filesize' . $filemax . '|' . $fileExt,
- ];
- parent::initialize();
- }
-
-
- public function Uploads()
- {
-
- $fileKey = array_keys(request()->file());
- for ($i = 0; $i < count($fileKey); $i++) {
-
- $file = request()->file($fileKey[$i]);
- try {
- validate($this->uploadValidate)->check(DataHelper::objToArray($file));
- $savename = \think\facade\Filesystem::disk('public')->putFile('uploads', $file);
- $savename = str_replace('\\', "/", $savename);
- $path[] = '/storage/' . $savename;
- } catch (\think\exception\ValidateException $e) {
- $path = '';
- $error = $e->getMessage();
- }
- }
- if (!empty($path)) {
- $result['code'] = 1;
-
- if (Request::param('responseType') == 'json') {
- $result["url"] = $path[0];
- } else {
- $result["url"] = $path;
- }
- $result['msg'] = lang('upload success');
- return $result;
- } else {
-
- $result['url'] = '';
- $result['msg'] = $error;
- $result['code'] = 0;
- return $result;
- }
- }
- }
|