Upload.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace app\admin\controller;
  3. class Upload extends \app\common\controller\Upload
  4. {
  5. /**
  6. * @api {post} /upload/image 上传图片
  7. * @apiGroup Upload
  8. * @apiVersion 1.0.0
  9. * @apiUse header
  10. * @apiUse lang
  11. *
  12. * @apiParam {File} file 图像文件的路径(本地路径)
  13. * - 文件大小限制:最大 20MB。
  14. * - 支持图像格式:`jpg`, `jpeg`, `png`,`webp`。
  15. */
  16. public function uploadFile()
  17. {
  18. $type = request()->input('type');
  19. //商品分类上传图片要求尺寸是750*750
  20. if ($type && $type == 'category') {
  21. $image = request()->file('file');
  22. if ($image && $image->isValid()) {
  23. $imageSize = getimagesize($image->getRealPath());
  24. $width = $imageSize[0];
  25. $height = $imageSize[1];
  26. if ($width != 750 || $height != 750) {
  27. return $this->error("上传文件的图片大小不合符标准,标准尺寸为750×750。");
  28. }
  29. }
  30. }
  31. return parent::uploadFile();
  32. }
  33. }