Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-03-04
7
Medium Priority
?
331 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 

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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.
Suggested Courses

877 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