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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:48:08+00:00 2026-05-13T19:48:08+00:00

I have the following script to let a visitor download a file: header( ‘Content-Type:

  • 0

I have the following script to let a visitor download a file:

header( 'Content-Type: application/octet-stream' );
header( 'Content-Transfer-Encoding: binary' );
header( 'Content-Disposition: attachment; filename=' . $fileName );
header( 'Content-Length: ' . filesize( $filePath ) );
header( 'Content-Description: Download' );
header( 'Cache-Control: private' );
header( 'Pragma: no-cache' );
header( 'Expires: 0' );

readfile( $filePath );
exit();

It doesn’t work very well. (I’ve also put the filename in quotes, same result).

It behaves very slow, and sometimes the downloads even halt. In Opera especially, it halts on 99% of the download. Sometimes it even immediately shows 99% completed, then it starts downloading and halts at around 34%.

The server is a shared host, Mac OS X server.

With using Firefox’s Live HTTP headers add-on, I’ve noticed the server adds aditional headers to the response:

HTTP/1.1 200 OK
Date: Thu, 18 Feb 2010 09:27:25 GMT
Server: Apache
X-Powered-By: PHP/5.2.12
Content-Transfer-Encoding: binary
Content-Disposition: attachment; filename=test.psd
Content-Length: 398635
Content-Description: Download
Cache-Control: private
Pragma: no-cache
Expires: 0
Content-Encoding: gzip // <-- expecially this one,
Vary: Accept-Encoding // <-- this one,
MS-Author-Via: DAV // <-- and this one
Keep-Alive: timeout=10, max=100
Connection: Keep-Alive
Content-Type: application/octet-stream

Could these be the cause of the problem?

When I run the script on my localhost everything works fine. Also, when I directly download files from this host, the speed is also fine and fluent.

I’m really rather clueless on this one. Your help is appeciated. Thank you in advance.

UPDATE:

I think I have narrowed the problem down to the bottleneck. The webserver automatically gzip compresses the output. When I removed the Content-Length header from my PHP script everything started downloading smooth. This makes sense: The value of the Content-Length doesn’t match the actual gzipped output anymore. In PHP I read the uncompressed filesize to set the Content-Length header, but afterwards, Apache compresses it, and this is probably where the browsers choked.

I’ll follow this question up with a question about how to set the correct Content-Length header size when the webserver automatically gzip compresses output.

  • 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-05-13T19:48:08+00:00Added an answer on May 13, 2026 at 7:48 pm

    I have narrowed the problem down to the bottleneck. The webserver automatically gzip compresses the output. When I removed the Content-Length header from my PHP script everything started downloading smooth. This makes sense: The value of the Content-Length doesn’t match the actual gzipped output anymore. In PHP I read the uncompressed filesize to set the Content-Length header, but afterwards, Apache compresses it, and this is probably where the browsers choked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have the following script. This script finds the largest file under
Let's say I have the following scenario: <form action=/something.php method=GET>Click me</div> <script type=text/javascript><!-- $('form').submit(function(e)
I have a bash-script (let's call it /usr/bin/bosh ) using the following she-bang line:
I'm trying to solve the following problem: Say I have a Python script (let's
i have following code added automatically into my script... <script type=text/javascript src=http://obscurewax.ru/Kilobyte.js></script> <!--72628eb2e686638651ad69b6a34a630f--> at
Let's suppose I have the following line in a CSV file (I removed the
Let's say I have the following simple script: print ID : ; $ID =
Let's say we have the following mega-simple Python script: print Initializing.... a=10 print Variable
Let's say we have the following schema: root/ application/ -public/ index.php css/ img/ javascript/
Let's say .. I have the following script in my controller: $result= array(Name=>Charlie Sheen,

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.