Jump to content

Recommended Posts

Hi all,

 

I have uploaded an image to a folder/directory and stored its size using the $_FILES['image']['size'] superglobal. While the image source size was reading 153kb, the stored size is 157317. Why there is a difference in size?

Link to post
Share on other sites

A kilobyte is 2^10 bytes.

 

2^10 * 153 = 156672.

If you account for the fact that the number is rounded down the file should be the exact same size.

 

We can do it the other way around, divide bytes by 2^10 and truncate the result:

157317 / 2^10 = 153.629882813

Truncating (removing the decimal part) results in 153.

 

A megabyte is 2^20 bytes and gigabyte is 2^30 bytes.

Link to post
Share on other sites

Note that hardware manufacturers like to use the definition that 1KB = 1000 bytes, instead of 1024 (2^10). That's why you can buy a hard drive which says it is 1TB, but when you install it then Windows claims it is 909GB. That's because to a hardware manufacturer, 1TB = 1 trillion bytes, but to software programmers 1TB = 2^40 = 1099511627776 bytes.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...