Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8196159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:23:23+00:00 2026-06-07T05:23:23+00:00

I would like to download a file with Curl. The problem is that the

  • 0

I would like to download a file with Curl.
The problem is that the download link is not direct, for example:

http://localhost/download.php?id=13456

When I try to download the file with curl, it download the file download.php!

Here is my curl code:

        ###
        function DownloadTorrent($a) {
                    $save_to = $this->torrentfolder; // Set torrent folder for download
                    $filename = str_replace('.torrent', '.stf', basename($a));

                    $fp = fopen ($this->torrentfolder.strtolower($filename), 'w+');//This is the file where we save the information
                    $ch = curl_init($a);//Here is the file we are downloading
                    curl_setopt($ch, CURLOPT_ENCODING, "gzip"); // Important 
                    curl_setopt($ch, CURLOPT_TIMEOUT, 50);
                    curl_setopt($ch, CURLOPT_URL, $fp);
                    curl_setopt($ch, CURLOPT_HEADER,0); // None header
                    curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); // Binary trasfer 1
                    curl_exec($ch);
                    curl_close($ch);
                    fclose($fp); 
    }

Is there a way to download the file without knowing the path?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:23:25+00:00Added an answer on June 7, 2026 at 5:23 am

    You may try CURLOPT_FOLLOWLOCATION

    TRUE to follow any “Location: ” header that the server sends as part
    of the HTTP header (note this is recursive, PHP will follow as many
    “Location: ” headers that it is sent, unless CURLOPT_MAXREDIRS is
    set).

    So it will result into:

    function DownloadTorrent($a) {
        $save_to = $this->torrentfolder; // Set torrent folder for download
        $filename = str_replace('.torrent', '.stf', basename($a));
    
        $fp = fopen ($this->torrentfolder.strtolower($filename), 'w+');//This is the file where we save the information
        $ch = curl_init($a);//Here is the file we are downloading
        curl_setopt($ch, CURLOPT_ENCODING, "gzip"); // Important 
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 50);
        curl_setopt($ch, CURLOPT_FILE, $fp);
        curl_setopt($ch, CURLOPT_HEADER,0); // None header
        curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); // Binary transfer 1
        curl_exec($ch);
        curl_close($ch);
        fclose($fp); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file (*.lwxl) that I would like for users to download a
I would like to download an mp3 file from some site, save it to
I would like to use standard ASP.NET file download response, like in other Stack
I would like to know if it's possible to download a file from a
i would like to create a Rails controller that download a serie of jpg
I am making a PHP script that will download a file given a name
I would like to download Tortoise SVN 'Show Log' info into a file (I
I would like to download all blobs as a single zipped file (or another
I would like to download a pdf file from the internet and save it
I would like to download a file without using NSURL/NSURLDownload/CFNetwork. I would like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.