Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-04
7
Medium Priority
?
329 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
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 …

721 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