Solved

Using Filesize in PHP does not match Content-Length.  Due to 64-bit OS?

Posted on 2011-03-04
7
313 Views
Last Modified: 2012-05-11
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?

Thanks.
0
Comment
Question by:Akitin
  • 4
  • 3
7 Comments
 
LVL 15

Expert Comment

by:gplana
ID: 35038822
The number of bits of the processor doesn't matters here. I suppose is a character-set issue. If you use an ASCII character set (such as ISO-8859-1) every character will fit on a byte. But if you use Unicode encoded in UTF-16, every character will need 2 bytes.

Please review the header on your HTML page, and let me know if I am right.

Hope it helps.
0
 

Accepted Solution

by:
Akitin earned 0 total points
ID: 35038929
It looks like the file stores information not as UTF-16, but delivery is in UTF-16.  How do I set output character-set?  Also, the reason I started working on this is because we would observe the same behavior when serving binary files.  That is content-length that was served using filesize() did not match the content-length of the file that was actually served.  Is there a solution for how to deal with that situation?
0
 
LVL 15

Expert Comment

by:gplana
ID: 35039339
You can add another http header: content-type="text/html; charset=utf-8"
If you want to send binary data, use content-type="application/octet-stream"

Hope it helps.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:Akitin
ID: 35039440
We are using MOV, so Content-type: video/quicktime should work, correct?
0
 
LVL 15

Expert Comment

by:gplana
ID: 35039622
Yes, that's correct
0
 

Author Closing Comment

by:Akitin
ID: 36038882
Found a solution
0
 
LVL 15

Expert Comment

by:gplana
ID: 36004790
Sorry, but I think comments #35038822, #35039339 and #35039622 helped to solve this question. I wonder if some points could be assigned to these comments.

Thank you.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SSL Certificate for IIS7 Site 2 56
Could not load file or assembly 'Microsoft.Web.Infrastructure 4 33
PHP Mail error 3 26
How to delete values from an array using php 4 22
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question