j.silver 0 Posted November 25, 2016 Report Share Posted November 25, 2016 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? Quote Link to post Share on other sites
Ingolme 1,019 Posted November 25, 2016 Report Share Posted November 25, 2016 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. Quote Link to post Share on other sites
justsomeguy 1,135 Posted November 28, 2016 Report Share Posted November 28, 2016 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. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.