UploadService.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\service\api\upload;
  12. use app\dict\sys\FileDict;
  13. use app\dict\sys\StorageDict;
  14. use app\service\core\upload\CoreUploadService;
  15. use core\base\BaseApiService;
  16. use core\exception\UploadFileException;
  17. use Exception;
  18. /**
  19. * 用户服务层
  20. * Class BaseService
  21. * @package app\service
  22. */
  23. class UploadService extends BaseApiService
  24. {
  25. private $root_path = 'file';
  26. private $cate_id = 0;
  27. /**
  28. * 附件库上传图片
  29. * @param $file
  30. * @return array
  31. * @throws Exception
  32. */
  33. public function image($file)
  34. {
  35. $dir = $this->root_path . '/' . 'image' . '/' . date('Ym') . '/' . date('d');
  36. $core_upload_service = new CoreUploadService();
  37. return $core_upload_service->image($file, 0, $dir, $this->cate_id);
  38. }
  39. /**
  40. * 附件库上传视频
  41. * @param $file
  42. * @return array
  43. * @throws Exception
  44. */
  45. public function video($file)
  46. {
  47. $dir = $this->root_path . '/' . 'video' . '/' . date('Ym') . '/' . date('d');
  48. $core_upload_service = new CoreUploadService();
  49. return $core_upload_service->video($file, 0, $dir, $this->cate_id);
  50. }
  51. /**
  52. * 文件上传
  53. * @param $file
  54. * @param string $type
  55. * @return array
  56. * @throws Exception
  57. */
  58. public function document($file, string $type = '')
  59. {
  60. if(!in_array($type, FileDict::getSceneType()))
  61. throw new UploadFileException('UPLOAD_TYPE_ERROR');
  62. $dir = $this->root_path.'/document/'.$type.'/'.date('Ym').'/'.date('d');
  63. $core_upload_service = new CoreUploadService();
  64. return $core_upload_service->document($file, 0, $type, $dir, StorageDict::LOCAL);
  65. }
  66. }