@@ -29,10 +29,8 @@ final class FileUpload
2929{
3030 use Nette \SmartObject;
3131
32- public const ImageMimeTypes = ['image/gif ' , 'image/png ' , 'image/jpeg ' , 'image/webp ' ];
33-
34- /** @deprecated use FileUpload::ImageMimeTypes */
35- public const IMAGE_MIME_TYPES = self ::ImageMimeTypes;
32+ /** @deprecated */
33+ public const IMAGE_MIME_TYPES = ['image/gif ' , 'image/png ' , 'image/jpeg ' , 'image/webp ' ];
3634
3735 /** @var string */
3836 private $ name ;
@@ -214,12 +212,20 @@ function (string $message) use ($dest): void {
214212
215213
216214 /**
217- * Returns true if the uploaded file is a JPEG, PNG, GIF, or WebP image .
215+ * Returns true if the uploaded file is an image supported by PHP .
218216 * Detection is based on its signature, the integrity of the file is not checked. Requires PHP extension fileinfo.
219217 */
220218 public function isImage (): bool
221219 {
222- return in_array ($ this ->getContentType (), self ::ImageMimeTypes, true );
220+ $ flag = imagetypes ();
221+ $ types = array_filter ([
222+ $ flag & IMG_GIF ? 'image/gif ' : null ,
223+ $ flag & IMG_JPG ? 'image/jpeg ' : null ,
224+ $ flag & IMG_PNG ? 'image/png ' : null ,
225+ $ flag & IMG_WEBP ? 'image/webp ' : null ,
226+ $ flag & 256 ? 'image/avif ' : null , // IMG_AVIF
227+ ]);
228+ return in_array ($ this ->getContentType (), $ types , true );
223229 }
224230
225231
0 commit comments