CrawlerAction.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Services\Ueditor;
  3. class CrawlerAction
  4. {
  5. protected $config;
  6. protected $action;
  7. public function __construct($config, $action)
  8. {
  9. $this->config = $config;
  10. $this->action = $action;
  11. }
  12. public function doCrawler()
  13. {
  14. /* 上传配置 */
  15. $config = array(
  16. "pathFormat" => $this->config['catcherPathFormat'],
  17. "maxSize" => $this->config['catcherMaxSize'],
  18. "allowFiles" => $this->config['catcherAllowFiles'],
  19. "oriName" => "remote.png"
  20. );
  21. $fieldName = $this->config['catcherFieldName'];
  22. /* 抓取远程图片 */
  23. $list = array();
  24. if (isset($_POST[$fieldName])) {
  25. $source = $_POST[$fieldName];
  26. } else {
  27. $source = $_GET[$fieldName];
  28. }
  29. foreach ($source as $imgUrl) {
  30. $item = new UploaderService($imgUrl, $config, "remote");
  31. $info = $item->getFileInfo();
  32. array_push($list, array(
  33. "state" => $info["state"],
  34. "url" => $info["url"],
  35. "size" => $info["size"],
  36. "title" => htmlspecialchars($info["title"]),
  37. "original" => htmlspecialchars($info["original"]),
  38. "source" => htmlspecialchars($imgUrl)
  39. ));
  40. }
  41. /* 返回抓取数据 */
  42. return json_encode(array(
  43. 'state' => count($list) ? 'SUCCESS' : 'ERROR',
  44. 'list' => $list
  45. ));
  46. }
  47. }