*/
protected $allowSvgImage = false;
+ /**
+ * maximum filesize for each uploaded file
+ * @var null|number
+ */
+ protected $maximumFilesize;
+
/**
* @inheritDoc
*/
['maximum' => $this->getMaximum()]
));
}
+
+ if ($this->getMaximumFilesize() !== null) {
+ foreach ($this->getValue() as $file) {
+ $filesize = filesize($file->getLocation());
+ if ($filesize > $this->getMaximumFilesize()) {
+ $this->addValidationError(new FormFieldValidationError(
+ 'maximumFilesize',
+ 'wcf.form.field.upload.error.maximumFilesize',
+ [
+ 'maximumFilesize' => $this->getMaximumFilesize(),
+ 'file' => $file
+ ]
+ ));
+ }
+ }
+ }
}
/**
return $this->traitMaximum($maximum);
}
+ /**
+ * Sets the maximum filesize for each upload. If `null` is passed, the
+ * maximum filesize is removed.
+ *
+ * @param null|number $maximumFilesize maximum filesize
+ * @return static this field
+ *
+ * @throws \InvalidArgumentException if the given maximum filesize is no number or otherwise invalid
+ */
+ public function maximumFilesize($maximumFilesize = null) {
+ if ($maximumFilesize !== null) {
+ if (!is_numeric($maximumFilesize)) {
+ throw new \InvalidArgumentException("Given maximum filesize is no int, '" . gettype($maximumFilesize) . "' given.");
+ }
+ }
+
+ $this->maximumFilesize = $maximumFilesize;
+
+ return $this;
+ }
+
+ /**
+ * Returns the maximum filesize of each file or `null` if no maximum filesize
+ * has been set.
+ *
+ * @return null|number
+ */
+ public function getMaximumFilesize() {
+ return $this->maximumFilesize;
+ }
+
/**
* Sets the flag for `imageOnly`. This flag indicates whether only images
* can uploaded via this field. Other file types will be rejected during upload.
<item name="wcf.form.field.email"><![CDATA[E-Mail-Adresse]]></item>
<item name="wcf.form.field.email.error.invalidEmail"><![CDATA[Die Eingabe ist keine gültige E-Mail-Adresse.]]></item>
<item name="wcf.form.field.email.error.maximumLength"><![CDATA[Die angegebene E-Mail-Adresse{if $language} für die Sprache „{$language}“{/if} umfasst {#$length} Zeichen, sie darf aber nicht länger als {#$maximumLength} Zeichen sein.]]></item>
+ <item name="wcf.form.field.upload.error.maximumFilesize"><![CDATA[Die Datei „{$file->getFilename()}“ darf maximal {$maximumFilesize|filesize} groß sein.]]></item>
</category>
<category name="wcf.image">
<item name="wcf.image.coverPhoto"><![CDATA[Titelbild]]></item>
<item name="wcf.form.field.email"><![CDATA[Email Address]]></item>
<item name="wcf.form.field.email.error.invalidEmail"><![CDATA[The entered text is no valid email address.]]></item>
<item name="wcf.form.field.email.error.maximumLength"><![CDATA[The entered email address{if $language|isset} for language “{$language}”{/if} contains {#$length} character{if $length !== 1}s{/if} but it may not be longer than {#$maximumLength} character{if $maximumLength !== 1}s{/if}.]]></item>
+ <item name="wcf.form.field.upload.error.maximumFilesize"><![CDATA[The file “{$file->getFilename()}” may have a maximum size of {$maximumFilesize|filesize}.]]></item>
</category>
<category name="wcf.image">
<item name="wcf.image.coverPhoto"><![CDATA[Cover Photo]]></item>