比如图片链接地址如下: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
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号