Qiniu.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use app\common\model\Attachment;
  5. class Qiniu extends Backend
  6. {
  7. /**
  8. * 细目
  9. * @var string
  10. */
  11. protected $topic = 'default';
  12. public function initialize()
  13. {
  14. parent::initialize();
  15. }
  16. public function callback()
  17. {
  18. $data = $this->request->post();
  19. $params = [
  20. 'topic' => $this->topic,
  21. 'admin_id' => $this->auth->id,
  22. 'user_id' => 0,
  23. 'url' => $data['url'],
  24. 'width' => $data['width'] ?? 0,
  25. 'height' => $data['height'] ?? 0,
  26. 'name' => substr(htmlspecialchars(strip_tags($data['name'])), 0, 100),
  27. 'size' => $data['size'],
  28. 'mimetype' => $data['type'],
  29. 'storage' => 'qiniu',
  30. 'sha1' => $data['sha1']
  31. ];
  32. $attachment = new Attachment();
  33. $attachment->data(array_filter($params));
  34. $attachment->save();
  35. }
  36. }