UploadFile.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace app\admin\controller;
  3. use Tinywan\Storage\Storage;
  4. class UploadFile extends BaseController
  5. {
  6. /**
  7. * Notes:上传图片
  8. * @return \support\Response
  9. * User: yym
  10. * Date: 2022/7/28
  11. */
  12. public function uploadFile()
  13. {
  14. $category = $this->request->post('category', '');
  15. Storage::config(null, true, $category);
  16. $upload = Storage::uploadFile();
  17. $data = array();
  18. $config = config('plugin.tinywan.storage.app.storage');
  19. if(count($upload) == 1)
  20. {
  21. $data['http_url'] = $upload[0]['url'];
  22. $data['root_url'] = str_replace($config[$config['default']]['domain'], '', $upload[0]['url']);
  23. $data['mime_type'] = $upload[0]['mime_type'];
  24. }
  25. if(count($upload) > 1)
  26. {
  27. foreach ($upload as $k => $row)
  28. {
  29. $data[$k]['url'] = $row['url'];
  30. $data[$k]['root_url'] = str_replace($config[$config['default']]['domain'], '', $row['url']);
  31. $data[$k]['name'] = $row['origin_name'];
  32. }
  33. }
  34. return json_success($data, '上传成功');
  35. }
  36. }