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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:43:36+00:00 2026-06-02T04:43:36+00:00

I have problem with downloading files via PHP. The funny thing is that I

  • 0

I have problem with downloading files via PHP.

The funny thing is that I can not trace the problem. The code works good for some websites and not good with other. It is loop in PHP that downloads the backup files from websites (there is delay with sleep before requests).

Why I can not trace the problem?
Because when I run manually the code, it works (downloads the file). And when it is run by CRON, sometimes it downloads the file, sometimes it does NOT download the file (only downloads 2 empty new lines).

The download is with curl (I have also tried with different code with fsockopen and fread).

Does anyone have an idea on how I can solve this?

Headers are removed with CURL by setting the correct option.

function fetch_url($url) {
    $c = curl_init();
    curl_setopt($c, CURLOPT_URL, $url);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($c, CURLOPT_TIMEOUT, 20);

    if ($cookiejar != '')  {
        curl_setopt($c, CURLOPT_COOKIEJAR, $cookiejar);
        curl_setopt($c, CURLOPT_COOKIEFILE, $cookiejar);
    }

    curl_setopt($c, CURLOPT_HEADER , false);
    curl_setopt($c, CURLOPT_SSL_VERIFYHOST , false);
    curl_setopt($c, CURLOPT_SSL_VERIFYPEER , false);
    curl_setopt($c, CURLOPT_FOLLOWLOCATION , true);
    curl_setopt($c, CURLOPT_AUTOREFERER , true);
    curl_setopt($c, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12');
    $con = curl_exec($c);
    curl_close($c);
    return $con;
}

echo fetch_url('http://www.example.com/zip.zip');
  • 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-02T04:43:37+00:00Added an answer on June 2, 2026 at 4:43 am

    Try using http://www.php.net/manual/en/function.curl-getinfo.php to display information about the curl request

    echo curl_errno($c);
    print_r(curl_getinfo($c));
    

    Also, Maybe it’s in your code elsewhere, but I’m not seeing any content type headers for your echoing of the file

    $file = fetch_url('http://www.example.com/zip.zip');
    header('Content-type: application/zip');
    header('Content-Disposition: attachment; filename="zip.zip"');
    header("Content-length: " . strlen($file));
    echo $file;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with ie8 As ALWAYS. its not downloading rtf files i
I have a problem downloading particular file types by WebClient. So there are no
I have problem with fancybox. I want to write a function that will run
i have problem with libhid . i found that there 2 way 4 accessing
I am downloading a bunch of images via ASINetworkQueue . I have no problems
I have list of files stored inside arraylist that I need to download in
I have to write a php script to download potentially large files. The file
I have a PHP script which fetches data from Salesforce via the Salesforce API
So I am trying to serve large files via a PHP script, they are
I have a problem, which I do not seem to be able to solve...

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.