? Header ("Content-type:image/jpeg"); function Read_url ($STR) { $file =fopen ($str, "R"); while (!feof ($file)) { $result. =fgets ($file, 9999); } Fclose ($file); return $result; } function Save_img ($STR) { $result =read_url ($STR); $result =str_replace ("" "," ", $result); $result =str_replace ("'", "", $result); Preg_match_all ('/|>)/I ', $result, $matches); foreach ($matches [1] as $value) { echo $value. " <br>n "; Grabimage ($value, $filename = ""); } } $url is the full URL address of the remote picture and cannot be empty. $filename is an optional variable: If NULL, local file names are based on time and date Automatically generated. function Grabimage ($url, $filename = "") { if ($url = = ""): return false;endif; $path = "download/"; Specify Storage Folder If the file does not exist, it is created; if (!file_exists ($path)) { mkdir ($path); } if ($filename = = "") { $ext =STRRCHR ($url, "."); if ($ext!= ". gif" && $ext!= ". jpg"): return false;endif; $filename = $path. Date ("Dmyhis"). $ext; } Ob_start (); ReadFile ($url); $img = Ob_get_contents (); Ob_end_clean (); $size = strlen ($img); $FP 2= @fopen ($filename, "a"); Fwrite ($fp 2, $img); Fclose ($fp 2); return $filename; } Save_img ("Http://www.111cn.net"); ?> |