Content-Length header always zero

时光总嘲笑我的痴心妄想 提交于 2019-11-29 12:17:41

Check for transfer-encoding header. If the transfer encoding is chunked, then the Content-Length field will not be set

Possible causes, is that ZendServer does not do chunked encoding, whereas Apache does

See the following links for details

http://en.wikipedia.org/wiki/Chunked_transfer_encoding

http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html

Gumbo

Make sure that the file really exists under the specified path (is_file checks both the existance and if the file is a regular file) and is readable (is_readable) before sending it to the client. filesize returns false if an error occured. So that might be the cause of your 0 value or empty value for Content-Length.

And, as Ferdinand Beyer already mentioned, make sure that your script is portable and can handle different environments.

Are you sure the file exists on the production server? Maybe it's a case sensitivity issue (e.g, "File" and "file" are the same on Windows, but different on UNIX)? Does the user running Apache/PHP have read access?

Do you get any errors if you enable errors?

error_reporting(E_ALL);
ini_set('display_errors', '1');

A problem may be that Apache is gzipping your download, taking care of correcting the Content-Length, or in your case, removing that header and adding

Content-Encoding: chunked

You can add a .htaccess RewriteRule to disable gzip:

RewriteRule . - [E=no-gzip:1]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!