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 8756961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:11:39+00:00 2026-06-13T14:11:39+00:00

I try to download file using a php-script from an URL like the following:

  • 0

I try to download file using a php-script from an URL like the following:

http://www.xcontest.org/track.php?t=2avxjsv1.igc

The code I use looks like the following, but it produces empty download files only:

$DLFile= "testfile.igc";
$DLURL="http://www.xcontest.org/track.php?t=2avxjsv1.igc"; 
$fp = fopen ($DLFile, 'w+');
$ch = curl_init($DLURL);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
curl_close($ch);
fclose($fp);

An other strange thing is when entering the URL in the web browser I don’t get the file. It can I could only download the file when clicking the link on the web site!.

Any advice is very appreciated!

  • 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-13T14:11:40+00:00Added an answer on June 13, 2026 at 2:11 pm

    Give this a go

    <?php
    
        $output_filename = "testfile.igc";
    
        $host = "http://www.xcontest.org/track.php?t=2avxjsv1.igc";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $host);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_AUTOREFERER, false);
        curl_setopt($ch, CURLOPT_REFERER, "http://www.xcontest.org");
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $result = curl_exec($ch);
        curl_close($ch);
    
        print_r($result); // prints the contents of the collected file before writing..
    
    
        // the following lines write the contents to a file in the same directory (provided permissions etc)
        $fp = fopen($output_filename, 'w');
        fwrite($fp, $result);
        fclose($fp);
    ?>
    

    #

    or if you want to put it within a loop for parsing several links… you need some functions.. here is a rough idea….

    <?php
    
        function collect_file($url){
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_VERBOSE, 1);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_AUTOREFERER, false);
            curl_setopt($ch, CURLOPT_REFERER, "http://www.xcontest.org");
            curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            $result = curl_exec($ch);
            curl_close($ch);
            return($result);
        }
    
        function write_to_file($text,$new_filename){
            $fp = fopen($new_filename, 'w');
            fwrite($fp, $text);
            fclose($fp);
        }
    
    
        // start loop here
    
        $new_file_name = "testfile.igc";
        $url = "http://www.xcontest.org/track.php?t=2avxjsv1.igc";
    
        $temp_file_contents = collect_file($url);
        write_to_file($temp_file_contents,$new_file_name)
    
        // end loop here
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my PHP code I try to download a file from a URL starting
I am try to download image files from url from the following code, but
I'm using readfile() in a php download script. When I try to download a
Try to download this page: http://www.4shared.com/get/B4AgMkcw/cookies.html I can use wget/firefox to get the whole
I am using the api twitterizer2 downloaded from http://code.google.com/p/twitterizer/downloads/list but when I try to
I'm using php to download files, rather than the file itself opening in a
I trying to get a file from an FTP server using ftp_get from PHP
I try to install json extension for php. Using pecl I get the following
I'm writing a script to download multiple FLACs from a website, and I'm using
I made a Bash script to download this page http://php.net/downloads.php and then search for

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.