public function isValid($file) : bool
{
$valid = false;
if (!$file instanceof \Jyxo\Input\Upload) {
$file = new \Jyxo\Input\Upload($file);
}
if ($file->tmpName() && $this->isUploaded($file->tmpName())) {
$valid = true;
} else {
$postMaxSize = ini_get('post_max_size');
$mul = substr($postMaxSize, -1);
$mul = $mul == 'M' ? 1048576 : ($mul == 'K' ? 1024 : ($mul == 'G' ? 1073741824 : 1));
if (isset($_SERVER['CONTENT_LENGTH'])) {
if ($_SERVER['CONTENT_LENGTH'] > $mul * (int) $postMaxSize && $postMaxSize) {
$this->error = _('The file you are trying to upload is too big.');
} else {
$this->setError($file->error());
}
} elseif ($this->requireUpload) {
$this->error = _('No file was uploaded.');
} else {
$this->failedEmpty = true;
}
}
return $valid;
}