php curl post 下载文件,求帮忙修改个php curl模拟post请求内容后并下载文件解决方案...

求帮忙修改个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写入文件中去。保存起来

------解决思路----------------------

$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 用迅雷打开为

12441368.jpg

相关文章

相关视频

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值