|
@@ -90,26 +90,42 @@ if($submit) {
|
|
|
$values = $field->values ?? [];
|
|
$values = $field->values ?? [];
|
|
|
|
|
|
|
|
if($type === "file") {
|
|
if($type === "file") {
|
|
|
- $file = (object) $_FILES[$name];
|
|
|
|
|
|
|
+ /** @var array $file */
|
|
|
|
|
+ $file = $_FILES[$name] ?? null;
|
|
|
|
|
+
|
|
|
|
|
+ if($file) {
|
|
|
|
|
+ $file_error = $file["error"];
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ $file_error = UPLOAD_ERR_NO_FILE;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- if(!$required && $file->error === UPLOAD_ERR_NO_FILE) continue;
|
|
|
|
|
- if($required && $file->error === UPLOAD_ERR_NO_FILE) {
|
|
|
|
|
|
|
+ if(!$required && $file_error === UPLOAD_ERR_NO_FILE) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if($required && $file_error === UPLOAD_ERR_NO_FILE) {
|
|
|
throw new Exception("$label is required.");
|
|
throw new Exception("$label is required.");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Detect upload error
|
|
// Detect upload error
|
|
|
- if($file->error !== UPLOAD_ERR_OK) throw new Exception(HTTP::getUploadErrorString($file->error));
|
|
|
|
|
|
|
+ if($file_error !== UPLOAD_ERR_OK) {
|
|
|
|
|
+ throw new Exception(HTTP::getUploadErrorString($file_error));
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// Get image details
|
|
// Get image details
|
|
|
- $size = @getimagesize($file->tmp_name);
|
|
|
|
|
- if(!$size) throw new Exception(sprintf(__("The uploaded file for %s is not an image."), $label));
|
|
|
|
|
|
|
+ $size = @getimagesize($file["tmp_name"]);
|
|
|
|
|
+ if(!$size) {
|
|
|
|
|
+ throw new Exception(sprintf(__("The uploaded file for %s is not an image."), $label));
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
[$width, $height, $type] = $size;
|
|
[$width, $height, $type] = $size;
|
|
|
- if($type !== IMAGETYPE_JPEG) throw new Exception(sprintf(__("The uploaded file for %s is not a JPEG."), $label));
|
|
|
|
|
|
|
+ if(in_array($type, [IMAGETYPE_JPEG, IMAGETYPE_PNG])) {
|
|
|
|
|
+ throw new Exception(sprintf(__("The uploaded file for %s is not a JPEG or PNG."), $label));
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// Resize image
|
|
// Resize image
|
|
|
- $output_image = Image::normalise($file->tmp_name);
|
|
|
|
|
|
|
+ $output_image = Image::normalise($file["tmp_name"]);
|
|
|
|
|
|
|
|
// Write image to disk
|
|
// Write image to disk
|
|
|
$output_path = $test->getDirectory() . "/" . $name . ".jpg";
|
|
$output_path = $test->getDirectory() . "/" . $name . ".jpg";
|