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

qqSuQi 2015-09-14 05:05:50
下面代码使用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;
...全文
232 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
qqSuQi 2015-09-16
  • 打赏
  • 举报
回复
非常感谢xuzuning版主和BingoVictor提供的技术支持,我之前利用A文件获得请求内容后再使用B文件下载A文件并自定义命名和后缀。 而版主提供的方法效率更高,更方便。谢谢了
xuzuning 2015-09-15
  • 打赏
  • 举报
回复
$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 2015-09-15
  • 打赏
  • 举报
回复
$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 用迅雷打开为
断点Bingo 2015-09-15
  • 打赏
  • 举报
回复
下载的文件名自己定义成.torrent的后缀 这个种子是 5.Flights.Up.2014.LIMITED.720p.BRRip.XviD.AC3-RARBG?
qqSuQi 2015-09-14
  • 打赏
  • 举报
回复
引用 1 楼 BingoVictor 的回复:
不要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文件
断点Bingo 2015-09-14
  • 打赏
  • 举报
回复
不要echo $ret; 把$ret写入文件中去。保存起来

20,359

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧