phpmaster57 Posted February 16, 2016 Share Posted February 16, 2016 So, 100MB is equal to 100000000 Bytes (in decimal), and 104857600 Bytes (in binary), for PHP which version would we use for checking max filesize. My current function: public function convertToBytes($from){ $number=substr($from,0,-1); switch(strtoupper(substr($from,-1))){ case "K": return $number*1024; case "M": return $number*pow(1024,2); case "G": return $number*pow(1024,3); case "T": return $number*pow(1024,4); case "P": return $number*pow(1024,5); default: return $from; } } This function converts 100MB to 104857600 bytes. But when comparing it against $_FILES['file']['size'] it will allow the user to upload a 104MB file instead of 100MB file how can we fix this? Quote Link to comment https://forums.phpfreaks.com/topic/300821-php-file-size/ Share on other sites More sharing options...
Jacques1 Posted February 16, 2016 Share Posted February 16, 2016 What's the problem? If you're doing the size check with your own function, simply change the factor 1024 to 1000 so that 100M is interpreted as 100,000,000. Or actually write down “100000000” so that there's never any ambiguity. Quote Link to comment https://forums.phpfreaks.com/topic/300821-php-file-size/#findComment-1531157 Share on other sites More sharing options...
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.