Set max file sizes on products

This commit is contained in:
Jérémy Munsch 2023-09-11 17:18:29 +02:00
parent 99f7545595
commit c450d71bed
No known key found for this signature in database
GPG key ID: 18361AF3BFEC0FEC
2 changed files with 9 additions and 0 deletions

View file

@ -69,6 +69,10 @@ trait HasDocumentAndPictureList
'mimetypes' => Str::of($this->autorisedMimTypes)->implode(' ou ')
]));
}
$maxSize = 6 * 1024 * 1024;
if (File::size($value) > $maxSize) {
$fail(trans(':attribute doit être inférieur à :size Mo', ['size' => $maxSize / (1024 * 1024)]));
}
}
/**

View file

@ -138,6 +138,11 @@ trait HasPicture
) {
$fail(trans(":attribute doit être une image de type 'image/jpeg,image/jpg,image/png,image/gif'"));
}
$filesize = \filesize($fileFullPath);
$maxSize = 6 * 1024 * 1024;
if ($filesize === false || $filesize > $maxSize) {
$fail(trans(':attribute doit être inférieur à :size Mo', ['size' => $maxSize / (1024 * 1024)]));
}
if (!($dimensions = \getimagesize($fileFullPath)) or !isset($dimensions[0]) or !isset($dimensions[1])) {
$fail(trans(":attribute impossible de valider les dimensions"));
} else {