Ajax.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // |
  4. // +----------------------------------------------------------------------
  5. // |
  6. // +----------------------------------------------------------------------
  7. // |
  8. // +----------------------------------------------------------------------
  9. // |
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | Ajax异步请求接口
  13. // +----------------------------------------------------------------------
  14. namespace app\index\controller;
  15. use app\api\controller\Common;
  16. use app\common\controller\Frontend;
  17. use think\Response;
  18. class Ajax extends Frontend
  19. {
  20. protected $noNeedLogin = ['upload'];
  21. protected $noNeedRight = ['*'];
  22. /**
  23. * 生成后缀图标
  24. */
  25. public function icon(): Response
  26. {
  27. $suffix = $this->request->request("suffix", 'file');
  28. $data = build_suffix_image($suffix);
  29. $header = ['Content-Type' => 'image/svg+xml'];
  30. $offset = 30 * 60 * 60 * 24; // 缓存一个月
  31. $header['Cache-Control'] = 'public';
  32. $header['Pragma'] = 'cache';
  33. $header['Expires'] = gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
  34. return Response::create($data)->header($header);
  35. }
  36. /**
  37. * 上传文件
  38. */
  39. public function upload()
  40. {
  41. $api = app(Common::class);
  42. return $api->upload();
  43. }
  44. }