koel/app/Rules/ImageData.php
2022-08-08 18:00:59 +02:00

22 lines
484 B
PHP

<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
class ImageData implements Rule
{
public function passes($attribute, $value): bool
{
return attempt(static function () use ($value) {
[$header,] = explode(';', $value);
return (bool) preg_match('/data:image\/(jpe?g|png|webp|gif)/i', $header);
}, false) ?? false;
}
public function message(): string
{
return 'Invalid DataURL string';
}
}