Please help modify PHP curl to simulate POST request content and download the file

Source: Internet
Author: User
The following code uses curl to simulate the POST request link directly after displaying the contents of the file, how to modify to not display the content and directly download the request to the. torrent format file?
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);// You need to change the content display to file download echo $ret;


Reply to discussion (solution)

Do not echo $ret;
Write the $ret to the file. Save it.

Do not echo $ret;
Write the $ret to the file. Save it.



Tried it.
Header ("Content-type:application/force-download");
$ret;
The download is the PHP blank file
Use
$filename = $ret;
Header ("Content-type:application/force-download");
Header ("content-disposition:attachment; Filename= ". basename ($filename));
ReadFile ($filename);
Then download a bunch of garbled PHP files

The downloaded filename itself is defined as the suffix of the. Torrent This seed is 5.FLIGHTS.UP.2014.LIMITED.720P.BRRIP.XVID.AC3-RARBG?

$ret = Curl_post ($header, $data, $url);//need to change the content display to file download $filename = ' x.torrent '; header ("content-type:application/ Force-download "); header (" Content-disposition:attachment; Filename= $filename ");  Echo $ret;
Download the x.torrent with Thunderbolt open for

$ret = Curl_post ($header, $data, $url);//need to change the content display to file download $filename = ' x.torrent '; header ("content-type:application/ Force-download "); header (" Content-disposition:attachment; Filename= $filename ");  Echo $ret;
Download the x.torrent with Thunderbolt open for

Thank you very much for the technical support provided by Xuzuning and Bingovictor, and I have previously used a file to obtain the requested content and then use the B file to download a file and customize the naming and suffix.
The methods provided by moderators are more efficient and more convenient. Thank you.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.