您好,欢迎访问一九零五行业门户网

有一个图片的下载链接,php如何下载图片到本地

比如图片链接地址如下:http://125.35.6.80:8080/ftba/itownet/download.do?method=downloadfile&fid=917d9f52486042a4829ea9392b801f6d&ssid=kv_l24clmshsqy7punwrga||
使用php如何自动的下载到本地,我使用file_get_contents和curl两种方法均未成功。
我使用的方法代码如下:
1)file_get_contents:
$img = file_get_contents(‘http://125.35.6.80:8080/ftba/itownet/download.do?method=downloadfile&fid=917d9f52486042a4829ea9392b801f6d&ssid=kv_l24clmshsqy7punwrga||’);
file_put_contents('1.jpg',$img);
2)curl
$ch = curl_init();
curl_setopt($ch, curlopt_post, 0);
curl_setopt($ch,curlopt_url,‘http://125.35.6.80:8080/ftba/itownet/download.do?method=downloadfile&fid=917d9f52486042a4829ea9392b801f6d&ssid=kv_l24clmshsqy7punwrga||’);
curl_setopt($ch, curlopt_returntransfer, 1);
$file_content = curl_exec($ch);
curl_close($ch);
$downloaded_file = fopen('1.jpg', 'w');
fwrite($downloaded_file, $file_content);
fclose($downloaded_file);
望指教,在此谢过。
回复讨论(解决方案) curl 缺少:
 curl_setopt($ch, curlopt_useragent, $_server['http_user_agent']);
file_get_contents 缺少第三个参数数:
$context = stream_context_create(array('http' => array('user_agent' => $_server['http_user_agent']))); 
http://blog.csdn.net/shrimpma/article/details/9816035
其它类似信息

推荐信息