mirror of
https://github.com/koel/koel
synced 2024-11-14 16:37:28 +00:00
26 lines
503 B
PHP
26 lines
503 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Rules;
|
||
|
|
||
|
use Illuminate\Contracts\Validation\Rule;
|
||
|
use Throwable;
|
||
|
|
||
|
class ImageData implements Rule
|
||
|
{
|
||
|
public function passes($attribute, $value): bool
|
||
|
{
|
||
|
try {
|
||
|
[$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';
|
||
|
}
|
||
|
}
|