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

求帮忙修改个php curl模拟post请求内容后并下载文件

下面代码使用curl模拟post请求链接后直接显示出了文件内容,如何修改成不显示内容而直接下载请求到的.torrent格式文件呢
function curl_post($header,$data,$url){ $ch = curl_init(); $res= curl_setopt ($ch, curlopt_url,$url); curl_setopt($ch, curlopt_ssl_verifyhost, false); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt ($ch, curlopt_header, 0); curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, $data); curl_setopt ($ch, curlopt_returntransfer, 1); curl_setopt($ch,curlopt_httpheader,$header); $result = curl_exec ($ch); curl_close($ch); if ($result == null) { return 0; } return $result;} $url = 'http://www.bttiantang.com/download4.php' ; $header = array(host:www.bttiantang.com, content-type:application/x-www-form-urlencoded, 'user-agent: mozilla/4.0 (compatible; msie .0; windows nt 6.1; trident/4.0; slcc2;)'); $data = 'action=download&id=26881&uhash=eecf3d3071a7b672c314bc39';$ret = curl_post($header, $data,$url);//需将内容显示修改为文件下载echo $ret;
回复讨论(解决方案) 不要echo $ret;
把$ret写入文件中去。保存起来
不要echo $ret;
把$ret写入文件中去。保存起来
试过使用
header(content-type: application/force-download);
$ret;
下载的是该php空白文件
使用
$filename=$ret;
header(content-type: application/force-download);
header(content-disposition: attachment; filename=.basename($filename));
readfile($filename);
则下载一堆乱码的php文件
下载的文件名自己定义成.torrent的后缀 这个种子是 5.flights.up.2014.limited.720p.brrip.xvid.ac3-rarbg?
$ret = curl_post($header, $data,$url);//需将内容显示修改为文件下载$filename = 'x.torrent';header(content-type: application/force-download);header(content-disposition: attachment; filename=$filename); echo $ret;

下载的 x.torrent 用迅雷打开为
$ret = curl_post($header, $data,$url);//需将内容显示修改为文件下载$filename = 'x.torrent';header(content-type: application/force-download);header(content-disposition: attachment; filename=$filename); echo $ret;

下载的 x.torrent 用迅雷打开为
非常感谢xuzuning版主和bingovictor提供的技术支持,我之前利用a文件获得请求内容后再使用b文件下载a文件并自定义命名和后缀。
而版主提供的方法效率更高,更方便。谢谢了
其它类似信息

推荐信息