<?PHP//header ("content-type:text/html; Charset=utf-8 ");@Ini_set(' Date.timezone ', ' Asia/shanghai ');@Set_time_limit(0);@Ini_set(' Memory_limit ', ' 100M ');$headurl= ' http://'.$_server[' Http_host '].$_server["Request_uri"];$headurl=substr($headurl, 0,Strrpos($headurl, '/') + 1);//---Download images to local _ generate the original folder path---//$savetxt=Date(' y-m-d h-i-s '). txt;//echo $savetxt. ' <br/> ';if(Ob_get_level() = = 0)Ob_start();Echo' <font style= ' color: #009900; " >downloading...</font><br/><br/> ';Echo Str_pad(', 4096). " \ n ";Ob_flush();Flush();Sleep(1);//$imgurls _array = file (' imgurlstest.php ');//Read each line in the file as an array element//$imgurls _array = Array_unique (Array_filter ($ Imgurls_array));$file 1= ' Imglist.txt ';$content 1=file_get_contents($file 1);$imgurls _array=Explode("\ r \ n",$content 1);//read each line in a file as an array element$imgurls _array=Array_unique(Array_filter($imgurls _array));if(!Empty($imgurls _array)){//---Download images to local _ generate the original folder path---// $success=Array(); Echo' <font style= ' color: #009900; " >have img Total: '.Count($imgurls _array) . ' </font><br/><br/> '; Echo Str_pad(', 4096). " \ n "; Ob_flush(); Flush(); Sleep(1); foreach($imgurls _array as $key=$imgurlval){ $imgurlval=Trim(Str_replace("\ r \ n", "",$imgurlval)); $temp= Get_images ($imgurlval); if($temp){ $success[] = ' <font style= ' color: #009900; " >success: <a style= "color: #009900;" href= ".$headurl.$temp.‘" > '.$headurl.$temp.‘ </a></font><br/> '; $f=fopen($savetxt, "a"); fwrite($f,$imgurlval." \ r \ n "); fclose($f); } } Echo' <font style= ' color: #009900; " >success total: '. @Count($success) . ' </font><br/><br/> '; Echo Str_pad(', 4096). " \ n "; Ob_flush(); Flush(); Sleep(1); $success=Array_filter($success); foreach($success as $key=$val){ Echo $val; }}functionGet_images ($img _url){ if(Empty($img _url))return false; $imgfile=PathInfo($img _url,pathinfo_basename); $imgdir=PathInfo($img _url,pathinfo_dirname); $imgdir=Preg_replace("~http://\w*\.* ([^/]*)/~i", "",$imgdir) . ‘/‘; !Is_dir($imgdir) && @mkdir($imgdir, 0777,true); $ext=STRRCHR($img _url,"."); if($ext! = ". gif" &&$ext! = ". jpg" &&$ext! = ". png" &&$ext! = ". bmp" &&$ext!= ". GIF "&&$ext!= ". JPG "&&$ext!= ". PNG "&&$ext!= ". BMP ")return false; $img _url=Trim($img _url); $img _url=Str_replace(', '%20 ',$img _url); $img _url=Str_replace(' & ', ' & ',$img _url); $curl _handle=Curl_init (); curl_setopt ($curl _handle, Curlopt_url,$img _url); curl_setopt ($curl _handle, Curlopt_header,false); curl_setopt ($curl _handle, Curlopt_useragent, "mozilla/5.0 (Windows NT 5.1; rv:12.0) gecko/20100101 firefox/12.0 "); curl_setopt ($curl _handle, Curlopt_returntransfer, 1); curl_setopt ($curl _handle, Curlopt_connecttimeout, 30); $img= Curl_exec ($curl _handle); Curl_close ($curl _handle); $handle= @fopen($imgdir.$imgfile, "W"); fwrite($handle,$img); fclose($handle); $down _img=$imgdir.$imgfile; return $down _img;}Ob_end_flush();?>
PHP download image generate original path and save downloaded picture path to TXT file