koel/app/Rules/ImageData.php

23 lines
484 B
PHP
Raw Normal View History

<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
class ImageData implements Rule
{
public function passes($attribute, $value): bool
{
2022-08-08 16:00:59 +00:00
return attempt(static function () use ($value) {
2020-12-22 20:11:22 +00:00
[$header,] = explode(';', $value);
2022-07-16 23:11:24 +00:00
return (bool) preg_match('/data:image\/(jpe?g|png|webp|gif)/i', $header);
2022-08-08 16:00:59 +00:00
}, false) ?? false;
}
public function message(): string
{
return 'Invalid DataURL string';
}
}