php批量下载图片,网上找的代码,不好使
<br />function project_statistics(){<br /> echo "11111";<br /> $url = "http://www.xxx.com:81/upload/image"; <br /> $content=file_get_contents($url); <br /> $reg="/<img .*?src=\"(.*?)\".*? alt="php批量下载图片,网上觅的代码,不好使" >/"; <br /> <br /> preg_match_all($reg,$content,$matches); <br /> <br /> $path = '../download/img'; <br /> if(!file_exists($path)){ <br /> mkdir($path, 0777); <br /> } <br /><br /> function downImage($url,$filename="") { <br /> if($url=="") return false; <br /> <br /> if($filename=="") { <br /> $ext=strrchr($url,"."); <br /> if($ext!=".gif" && $ext!=".jpg" && $ext!=".png" && $ext!="jpeg") return false; <br /> $filename=date("YmdHis").$ext; <br /> } <br /> <br /> ob_start(); <br /> //make file that output from url goes to buffer <br /> readfile($url); <br /> //file_get_contents($url); 这个方法不行的!!!只能用readfile <br /> $img = ob_get_contents(); <br /> ob_end_clean(); <br /> <br /> [email protected]($filename, "a");//append <br /> fwrite($fp,$img); <br /> <br /> fclose($fp); <br /> <br /> return $filename; <br /> <br /> }<br /> for($i = 0;$i < count($matches[1]);$i ++){ <br /> <br /> /*explode <br /> $url_arr[$i] = explode('/', $matches[1][$i]); <br /> $last = count($url_arr[$i])-1; <br /> */ <br /> <br /> //strrchr <br /> $filename = strrchr($matches[1][$i], '/'); <br /> <br /> downImage($matches[1][$i],$path.$filename); <br /> //downImage($matches[1][$i],$path.'/'.$url_arr[$i][$last]); <br /> } <br /> <br /><br />}<br />