0
0

action_crawler.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. "pathFormat" => $CONFIG['catcherPathFormat'],
  13. "maxSize" => $CONFIG['catcherMaxSize'],
  14. "allowFiles" => $CONFIG['catcherAllowFiles'],
  15. "oriName" => "remote.png"
  16. );
  17. $fieldName = $CONFIG['catcherFieldName'];
  18. /* 抓取远程图片 */
  19. $list = array();
  20. if (isset($_POST[$fieldName])) {
  21. $source = $_POST[$fieldName];
  22. } else {
  23. $source = $_GET[$fieldName];
  24. }
  25. foreach ($source as $imgUrl) {
  26. $item = new Uploader($imgUrl, $config, "remote");
  27. $info = $item->getFileInfo();
  28. array_push($list, array(
  29. "state" => $info["state"],
  30. "url" => $info["url"],
  31. "size" => $info["size"],
  32. "title" => htmlspecialchars($info["title"]),
  33. "original" => htmlspecialchars($info["original"]),
  34. "source" => htmlspecialchars($imgUrl)
  35. ));
  36. }
  37. /* 返回抓取数据 */
  38. return json_encode(array(
  39. 'state'=> count($list) ? 'SUCCESS':'ERROR',
  40. 'list'=> $list
  41. ));