D
D
devilsD2019-11-13 21:50:25
MIME types
devilsD, 2019-11-13 21:50:25

Laravel 6 How to properly validate svg?

Good afternoon. Faced the problem of svg validation.
I'm trying to validate by extension:
'icon' => 'max:50|mimes:svg',
But the icons are loaded only if there are lines in the file:

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

That is, if the svg document starts with the *svg* tag, then the image will not load.
Is it possible not to check the mime type, but just to do validation by extension?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jazzus, 2019-11-14
@devilsD

Why does svg start with some kind of tag? Let it start like it should. I had a similar situation when I did not skip docx with docx mime and the problem was in the self-made editor with which the file was created. To check by extension, make a Rule with a check

public function passes($attribute, $value)
{
  // проверка на совпадение расширения файла с svg
  return $value->getClientOriginalExtension() === File::EXTENSION__SVG;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question