Solved

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

Posted on 2011-03-04
7
326 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

636 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