mirror of
https://github.com/standardebooks/web.git
synced 2025-07-06 06:40:33 -04:00
Add the HttpInput::File() and HttpInput::Date() method
This commit is contained in:
parent
f28378de37
commit
98f45ea4e0
4 changed files with 46 additions and 28 deletions
|
@ -107,6 +107,30 @@ class HttpInput{
|
|||
return self::GetHttpVar($variable, HttpVariableType::Decimal, $set);
|
||||
}
|
||||
|
||||
public static function Date(HttpVariableSource $set, string $variable): ?DateTimeImmutable{
|
||||
/** @var ?DateTimeImmutable */
|
||||
return self::GetHttpVar($variable, HttpVariableType::DateTime, $set);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the absolute path of the requested file upload, or `null` if there isn't one.
|
||||
*
|
||||
* @throws Exceptions\InvalidFileUploadException If there is a file upload present, but the upload somehow failed.
|
||||
*/
|
||||
public static function File(string $variable): ?string{
|
||||
$filePath = null;
|
||||
|
||||
if(isset($_FILES[$variable]) && $_FILES[$variable]['size'] > 0){
|
||||
if(!is_uploaded_file($_FILES[$variable]['tmp_name']) || $_FILES[$variable]['error'] > UPLOAD_ERR_OK){
|
||||
throw new Exceptions\InvalidFileUploadException();
|
||||
}
|
||||
|
||||
$filePath = $_FILES[$variable]['tmp_name'] ?? null;
|
||||
}
|
||||
|
||||
return $filePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $variable
|
||||
* @return array<string>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue