LSformRule :: filesize : improve by avoiding to create a temporary file

This commit is contained in:
Benjamin Renard 2020-05-04 18:01:13 +02:00
parent 958c5b16a8
commit 07cdad29a4

View file

@ -39,9 +39,10 @@ class LSformRule_filesize extends LSformRule {
* @return boolean true si la valeur est valide, false sinon * @return boolean true si la valeur est valide, false sinon
*/ */
public static function validate ($value,$options,$formElement) { public static function validate ($value,$options,$formElement) {
$file = LSsession :: getTmpFile($value); // According to PHP doc, strlen() returns the number of bytes rather
// than the number of characters in a string.
$size = filesize($file); // See: https://www.php.net/manual/en/function.strlen.php
$size = strlen($value);
$maxSize = LSconfig :: get('params.maxSize', null, 'int', $options); $maxSize = LSconfig :: get('params.maxSize', null, 'int', $options);
if (is_int($maxSize) && $size > $maxSize) if (is_int($maxSize) && $size > $maxSize)