foreach ($_FILES['__files']['tmp_name'] as $id => $tmpName) {
if ($field->isImageOnly()) {
if (@getimagesize($tmpName) === false) {
- if (!$field->svgImagesAllowed() || !in_array(FileUtil::getMimeType($tmpName), [
+ if (!$field->svgImageAllowed() || !in_array(FileUtil::getMimeType($tmpName), [
'image/svg',
'image/svg+xml'
])) {
}
$allowedExtensions = ['jpeg', 'jpg', 'png', 'gif'];
- if ($field->svgImagesAllowed()) $allowedExtensions[] = 'svg';
+ if ($field->svgImageAllowed()) $allowedExtensions[] = 'svg';
if (!in_array(pathinfo($_FILES['__files']['name'][$id], PATHINFO_EXTENSION), $allowedExtensions)) {
$response['error'][$i++] = [
continue;
}
- $uploadFile = new UploadFile($tmpFile, $_FILES['__files']['name'][$id], true, false, $field->svgImagesAllowed());
+ $uploadFile = new UploadFile($tmpFile, $_FILES['__files']['name'][$id], true, false, $field->svgImageAllowed());
UploadHandler::getInstance()->addFileByInternalId($this->internalId, $uploadFile);
public $internalId = null;
/**
- * Indicates whether the field is image only.
+ * This flag indicates whether only images can uploaded via this field.
* @var boolean
*/
public $imageOnly = false;
/**
- * Indicates whether the field supports svg images.
- *
- * <strong>Heads up:</strong> svg images can contain code, therefore do not
+ * This flag indicates whether only images can uploaded via this field.
+ * <strong>Heads up:</strong> SVG images can contain bad code, therefore do not
* use this option, outside the acp or check the file whether remote code is contained.
- *
* @var boolean
*/
- public $allowSvgImages = false;
+ public $allowSvgImage = false;
/**
* UploadField constructor.
}
/**
- * Returns true, if the upload is image only.
+ * Returns `true` if only images can be uploaded via this field and returns `false` otherwise.
*
* @return boolean
*/
}
/**
- * Returns true, if svg images are allowed.
+ * Returns true, if the field can contain svg images in the image only mode.
*
* @return boolean
*/
- public function svgImagesAllowed() {
- return $this->allowSvgImages;
+ public function svgImageAllowed() {
+ return $this->allowSvgImage;
}
/**
}
/**
- * Set the image only flag.
+ * Sets the flag for `imageOnly`. This flag indicates whether only images
+ * can uploaded via this field. Other file types will be rejected during upload.
*
* @param boolean $imageOnly
*/
}
/**
- * Set the image only flag.
+ * Sets the flag for `allowSvgImage`. This flag indicates whether
+ * SVG images should be handled as image, if the upload field is
+ * image only (if this field is not image only, this method will
+ * throw an exception).
+ *
+ * <strong>Heads up:</strong> SVG images can contain bad code, therefore do not
+ * use this option, outside the acp or check the file whether remote code is contained.
+ *
+ * @param boolean $allowSvgImage
*
- * @param boolean $allowSvgImages
+ * @throws \BadMethodCallException if the imageOnly flag isn't set to true
*/
- public function setAllowSvgImages($allowSvgImages) {
- $this->allowSvgImages = $allowSvgImages;
+ public function setAllowSvgImage($allowSvgImage) {
+ if (!$this->isImageOnly()) {
+ throw new \BadMethodCallException('Allowing SVG images is only relevant, if the `imageOnly` flag is set to `true`.');
+ }
+
+ $this->allowSvgImage = $allowSvgImage;
}
}
use TMinimumFormField;
/**
- * imageOnly flag for the upload field.
+ * This flag indicates whether only images can uploaded via this field.
+ * <strong>Heads up:</strong> SVG images can contain bad code, therefore do not
+ * use this option, outside the acp or check the file whether remote code is contained.
* @var boolean
*/
protected $imageOnly = false;
/**
- * allowSvgImage flag.
+ * This flag indicates whether SVG images are treated as image in the image only mode.
* @var boolean
*/
protected $allowSvgImage = false;
$uploadField = new UploadField($this->getId());
$uploadField->maxFiles = $this->getMaximum();
$uploadField->setImageOnly($this->isImageOnly());
- $uploadField->setAllowSvgImages($this->svgImageAllowed());
+ $uploadField->setAllowSvgImage($this->svgImageAllowed());
return $uploadField;
}
}
/**
- * Sets the imageOnly flag for this field.
+ * Sets the flag for `imageOnly`. This flag indicates whether only images
+ * can uploaded via this field. Other file types will be rejected during upload.
*
* @param boolean $imageOnly
* @return static this field
}
/**
- * Sets the imageOnly flag for this field.
+ * Sets the flag for `allowSvgImage`. This flag indicates whether
+ * SVG images should be handled as image, if the upload field is
+ * image only (if this field is not image only, this method will
+ * throw an exception).
+ *
+ * <strong>Heads up:</strong> SVG images can contain bad code, therefore do not
+ * use this option, outside the acp or check the file whether remote code is contained.
*
* @param boolean $allowSvgImages
* @return static this field
}
/**
- * Returns true, if the field can contain svg images.
+ * Returns true, if the field can contain svg images in the image only mode.
*
* @return boolean
*/