求帮忙修改个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;
$ret = curl_post($header, $data,$url);//需将内容显示修改为文件下载$filename = 'x.torrent';header("Content-Type: application/force-download");header("Content-Disposition: attachment; filename=$filename"); echo $ret;
非常感谢xuzuning版主和BingoVictor提供的技术支持,我之前利用A文件获得请求内容后再使用B文件下载A文件并自定义命名和后缀。
而版主提供的方法效率更高,更方便。谢谢了

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot
