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?