1、fsockopen方法。
以下为引用的内容:
php
$url = “http://www.example.net/xxx/xxx.jpg”;
t = p a r s e u r l ( t = parse_url( t=parseurl(url);
$host = $t[‘host’];
$file = $t[‘path’];
f p = f s o c k o p e n ( fp = fsockopen( fp=fsockopen(host,80, $errno, e r r s t r , 30 ) ; i f ( errstr, 30); if( errstr,30);if(fp)
{
$header = “GET $file HTTP/1.1/r/n”;
$header .= “Host: $host/r/n”;
$header .= “User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; zh-CN; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1/r/n”;
h e a d e r . = “ R e f e r e r : h t t p : / / header .= “Referer: http:// header.=“Referer:http://host/r/n”;
h e a d e r . = “ C o n n e c t i o n : C l o s e / r / n / r / n ” ; f w r i t e ( header .= “Connection: Close/r/n/r/n”; fwrite( header.=“Connection:Close/r/n/r/n”;fwrite(fp, $header);
j p g = f o p e n ( jpg = fopen( jpg=fopen(path . basename( f i l e ) , “ w b ” ) ; w h i l e ( ! f e o f ( file), “wb”); while (!feof( file),“wb”);while(!feof(fp))
{
s = f g e t s ( s = fgets( s=fgets(fp,128);
fwrite( j p g , jpg, jpg,s);
}
fclose( j p g ) ; f c l o s e ( jpg); fclose( jpg);fclose(fp);
}
?>
2.curl方法。需要php中启用curl。
以下为引用的内容:
php
set_time_limit(0);
ini_set(’display_errors’,true);//Just in case we get some errors, let us know….
$host = “www.example.net”;
u r l s = a r r a y ( “ h t t p : / / urls=array( “http:// urls=array(“http://host/xxx/xxx.jpg”,
“http://$host/xxx/yyy.jpg”
);
$save_to=’./’;
m h = c u r l m u l t i i n i t ( ) ; f o r e a c h ( mh = curl_multi_init(); foreach ( mh=curlmultiinit();foreach(urls as $i => $url)
{
g = g= g=save_to.basename( u r l ) ; i f ( ! i s f i l e ( url); if(!is_file( url);if(!isfile(g))
{
c o n n [ conn[ conn[i]=curl_init($url);
f p [ fp[ fp[i]=fopen ( g , “ w b ” ) ; c u r l s e t ( g, “wb”); curl_set( g,“wb”);curlset(conn[ i ] , C U R L O P T U S E R A G E N T , “ M o z i l l a / 5.0 ( W i n d o w s ; U ; W i n d o w s N T 6.0 ; z h − C N ; r v : 1.9.0.1 ) G e c k o / 2008070208 F i r e f o x / 3.0.1 ″ ) ; c u r l s e t ( i], CURLOPT_USERAGENT, “Mozilla/5.0 (Windows; U; Windows NT 6.0; zh-CN; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1″); curl_set( i],CURLOPTUSERAGENT,“Mozilla/5.0(Windows;U;WindowsNT6.0;zh−CN;rv:1.9.0.1)Gecko/2008070208Firefox/3.0.1″);curlset(conn[ i ] , C U R L O P T R E F E R E R , “ h t t p : / / i], CURLOPT_REFERER, “http:// i],CURLOPTREFERER,“http://host”);
curl_set( c o n n [ conn[ conn[i], CURLOPT_FILE, f p [ fp[ fp[i]);
curl_set( c o n n [ conn[ conn[i], CURLOPT_HEADER ,0);
curl_set( c o n n [ conn[ conn[i], CURLOPT_CONNECTTIMEOUT,600);
curl_set( c o n n [ conn[ conn[i], CURLOPT_FOLLOWLOCATION, 1);
//curl_set( c o n n [ conn[ conn[i], CURLOPT_RETURNTRANSFER, 0);
//curl_set( c o n n [ conn[ conn[i], CURLOPT_VERBOSE, 0);
curl_multi_add_handle ( m h , mh, mh,conn[$i]);
}
}
do {
n = c u r l m u l t i e x e c ( n=curl_multi_exec( n=curlmultiexec(mh,KaTeX parse error: Expected 'EOF', got '}' at position 10: active); }̲ while (active); php程序员站
foreach ($urls as $i => KaTeX parse error: Expected '}', got 'EOF' at end of input: …_remove_handle(mh, c o n n [ conn[ conn[i]);
curl_close( c o n n [ conn[ conn[i]);
fclose ( f p [ fp[ fp[i]);
}
curl_multi_close($mh);
?>