koel/app/Rules/ImageData.php

26 lines
500 B
PHP
Raw Normal View History

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