Using Filesize in PHP does not match Content-Length. Due to 64-bit OS?
Posted on 2011-03-04
I encountered a curious problem. If I create a file that contains "abc", calling filesize( $file ) returns 3. But, if I set
header("Content-Length: ". filesize( $file ) );
My content gets cut off on the client. If I don't set content-length explicitly, I noticed that received content-length on the client side is twice the size of the value returned by filesize. Is this because PHP filesize is running as a 32-bit application, but the response is sent by a server as a 64-bit application resulting in each character taking up 8 bytes instead of 4? What is the correct way to set up PHP on IIS in a 64-bit environment so that filesize returns the correct value?