Solved

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

Posted on 2011-03-04
7
304 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

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

Expert Comment

by:gplana
Comment Utility
Yes, that's correct
0
 

Author Closing Comment

by:Akitin
Comment Utility
Found a solution
0
 
LVL 15

Expert Comment

by:gplana
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now