Upload.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\shopapi\controller;
  11. use app\model\upload\Album;
  12. use app\model\upload\Upload as UploadModel;
  13. /**
  14. * 上传管理
  15. * @author Administrator
  16. *
  17. */
  18. class Upload extends BaseApi
  19. {
  20. /**
  21. * 头像上传
  22. */
  23. public function image()
  24. {
  25. $upload_model = new UploadModel($this->site_id);
  26. $param = array (
  27. "thumb_type" => "",
  28. "name" => "file"
  29. );
  30. $path = $this->site_id > 0 ? "common/images/" . date("Ymd") . '/' : "common/images/" . date("Ymd") . '/';
  31. $result = $upload_model->setPath($path)->image($param);
  32. return $this->response($result);
  33. }
  34. /**
  35. * 上传 存入相册
  36. */
  37. public function album()
  38. {
  39. $token = $this->checkToken();
  40. if ($token[ 'code' ] < 0) return $this->response($token);
  41. $album_id = isset($this->params[ 'album_id' ]) ? $this->params[ 'album_id' ] : 0;
  42. $upload_model = new UploadModel($this->site_id);
  43. $album_model = new Album();
  44. $album_info = $album_model->getAlbumInfo([
  45. [ 'site_id', '=', $this->site_id ],
  46. [ 'is_default', '=', 1 ]
  47. ], 'album_id')[ 'data' ];
  48. if (empty($album_id)) {
  49. $album_id = $album_info[ 'album_id' ];
  50. }
  51. $param = array (
  52. "thumb_type" => [ "BIG", "MID", "SMALL" ],
  53. "name" => "file",
  54. "album_id" => $album_id,
  55. "is_thumb" => 1
  56. );
  57. $result = $upload_model->setPath("common/images/" . date("Ymd") . '/')->imageToAlbum($param);
  58. return $this->response($result);
  59. }
  60. /**
  61. * 视频上传
  62. * @return \multitype
  63. */
  64. public function video()
  65. {
  66. $upload_model = new UploadModel($this->site_id);
  67. $name = input("name", "");
  68. $param = array (
  69. "name" => "file"
  70. );
  71. $result = $upload_model->setPath("common/video/" . date("Ymd") . '/')->video($param);
  72. return $result;
  73. }
  74. }