action_crawler.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. if (defined('STATIC_DIR')) {
  19. $config['pathFormat'] = STATIC_DIR . $config['pathFormat'];
  20. }
  21. /* 抓取远程图片 */
  22. $list = array();
  23. if (isset($_POST[$fieldName])) {
  24. $source = $_POST[$fieldName];
  25. } else {
  26. $source = $_GET[$fieldName];
  27. }
  28. foreach ($source as $imgUrl) {
  29. $item = new Uploader($imgUrl, $config, "remote");
  30. $info = $item->getFileInfo();
  31. // 图片打水印
  32. $ext = array(
  33. '.jpg',
  34. '.png',
  35. '.gif'
  36. );
  37. if (in_array($info['type'], $ext)) {
  38. resize_img(ROOT_PATH . $info['url']); // 缩放大小
  39. watermark_img(ROOT_PATH . $info['url']); // 水印
  40. }
  41. array_push($list, array(
  42. "state" => $info["state"],
  43. "url" => $info["url"],
  44. "size" => $info["size"],
  45. "title" => htmlspecialchars($info["title"]),
  46. "original" => htmlspecialchars($info["original"]),
  47. "source" => htmlspecialchars($imgUrl)
  48. ));
  49. }
  50. /* 返回抓取数据 */
  51. return json_encode(array(
  52. 'state' => count($list) ? 'SUCCESS' : 'ERROR',
  53. 'list' => $list
  54. ));