action_crawler.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * 抓取远程图片
  4. * User: Jinqn
  5. * Date: 14-04-14
  6. * Time: 下午19:18
  7. */
  8. set_time_limit(0);
  9. include("Uploader.class.php");
  10. /* 上传配置 */
  11. $config = array(
  12. "siteid"=>$CONFIG['siteid'],
  13. "pathFormat" => $CONFIG['catcherPathFormat'],
  14. "maxSize" => $CONFIG['catcherMaxSize'],
  15. "allowFiles" => $CONFIG['catcherAllowFiles'],
  16. "oriName" => "remote.png"
  17. );
  18. $fieldName = $CONFIG['catcherFieldName'];
  19. /* 抓取远程图片 */
  20. $list = array();
  21. if (isset($_POST[$fieldName])) {
  22. $source = $_POST[$fieldName];
  23. } else {
  24. $source = $_GET[$fieldName];
  25. }
  26. foreach ($source as $imgUrl) {
  27. $item = new Uploader($imgUrl, $config, "remote");
  28. $info = $item->getFileInfo();
  29. array_push($list, array(
  30. "state" => $info["state"],
  31. "url" => $info["url"],
  32. "size" => $info["size"],
  33. "title" => htmlspecialchars($info["title"]),
  34. "original" => htmlspecialchars($info["original"]),
  35. "source" => htmlspecialchars($imgUrl)
  36. ));
  37. }
  38. /* 返回抓取数据 */
  39. return json_encode(array(
  40. 'state'=> count($list) ? 'SUCCESS':'ERROR',
  41. 'list'=> $list
  42. ));