以下载远程图片为例。
1、fsockopen方法
以下为引用的内容: $fp = fsockopen($host,80, $errno, $errstr, 30); $header = “GET $file HTTP/1.1\r\n”; fwrite($fp, $header); $jpg = fopen($path . basename($file), “wb”); fclose($fp);
|
curl方法。需要php中启用curl。
以下为引用的内容: $host = “www.example.net”; $save_to=’./’; $mh = curl_multi_init(); foreach ($urls as $i => $url) $fp[$i]=fopen ($g, “wb”); curl_setopt($conn[$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_multi_add_handle ($mh,$conn[$i]); do { foreach ($urls as $i => $url) curl_multi_close($mh);
|