UploadFile.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\admin\controller;
  3. use support\Storage;
  4. class UploadFile
  5. {
  6. /**
  7. * @Desc 上传文件
  8. * @Author Gorden
  9. * @Date 2024/2/26 13:22
  10. *
  11. * @return \support\Response
  12. */
  13. public function upload($config)
  14. {
  15. try {
  16. $res = Storage::uploadFile($config);
  17. $data = [
  18. 'url' => $res[0]['url'],
  19. 'path' => $config['path'] . date('Ymd') . '/' . $res[0]['save_name'],
  20. 'size' => $res[0]['size'],
  21. 'mime_type' => $res[0]['mime_type'],
  22. ];
  23. } catch (\Exception $e) {
  24. return json_fail('上传失败:' . $e->getMessage());
  25. }
  26. return json_success('上传成功', $data);
  27. }
  28. /**
  29. * @Desc 上传图片
  30. * @Author Gorden
  31. * @Date 2024/2/26 17:16
  32. *
  33. * @return \support\Response
  34. */
  35. public function image()
  36. {
  37. $config = [
  38. 'single_limit' => 1024 * 5,
  39. 'nums' => 1,
  40. 'include' => ['jpg', 'jpeg', 'png'],
  41. 'filePath' => 'storage/images/'
  42. ];
  43. return $this->upload($config);
  44. }
  45. /**
  46. * @Desc 上传视频
  47. * @Author Gorden
  48. * @Date 2024/2/26 17:16
  49. *
  50. * @return \support\Response
  51. */
  52. public function video()
  53. {
  54. $config = [
  55. 'single_limit' => 1024 * 1024 * 50,
  56. 'nums' => 1,
  57. 'include' => ['mp4'],
  58. 'filePath' => 'storage/videos/'
  59. ];
  60. return $this->upload($config);
  61. }
  62. }