So when uploading files in PHP I'm currently checking for errors in upload size against the php.ini file:
switch ($_FILES['file']['error']) {
case UPLOAD_ERR_OK:
break;
case UPLOAD_ERR_NO_FILE:
throw new RuntimeException('No file sent.');
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
throw new RuntimeException('Exceeded filesize limit.');
default:
throw new RuntimeException('Unknown errors.');
}
And then checking them manually:
$max_size = "10490000";
if ($_FILES['file']['size'] > $max_size) {
throw new RuntimeException('Exceeded filesize limit.');
}
Is this second step necessary? Or is it sufficient just to check the errors.
Alternatively, if it is necessary, can I safely do something like this for the second check:
$max_size = (int)(ini_get('upload_max_filesize'));