PHP practical general method to obtain remote images

WBOY
Release: 2016-07-25 08:45:17
Original
999 people have browsed it
  1. function auto_save_image($body){
  2. $img_array = explode('&',$body);
  3. /*$img_array = array();
  4. preg_match_all("/(src)=["|'| ]{0,}(http://(.*).(gif|jpg|jpeg|bmp|png))["|'| ]{0,}/isU", $body, $img_array);
  5. $img_array = array_unique($img_array[2]);*/ //也可以自动匹配
  6. set_time_limit(0);
  7. $imgPath = "uploads/allimg/".date("Ymd")."/";
  8. $milliSecond = strftime("%H%M%S",time());
  9. if(!is_dir($imgPath)) @mkdir($imgPath,0777);
  10. foreach($img_array as $key =>$value)
  11. {
  12. $value = trim($value);
  13. $get_file = @file_get_contents($value);
  14. $rndFileName = $imgPath."/".$milliSecond.$key.".".substr($value,-3,3);
  15. if($get_file)
  16. {
  17. $fp = @fopen($rndFileName,"w");
  18. @fwrite($fp,$get_file);
  19. @fclose($fp);
  20. }
  21. $body = @ereg_replace($value, $rndFileName, $body);
  22. }
  23. return $body;
  24. }
复制代码

php


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template