Search code examples
phpsvggraphicsmagick

identify valid SVG using PHP


I need to check an upload for file type SVG. Unfortunately, there's no IMAGETYPE_SVG and finfo_file does not work on my machine. How can I make sure the upload is valid? However, I do have access to GraphicsMagick via system()


Solution

  • I have found a solution using GraphicsMagick:

    $valid = FALSE;
    @exec("gm identify +ping filename", $result);
    if (is_array($result)) {
        if (in_array("MVG", explode(" ", implode(" ", $result))) || in_array("SVG", explode(" ", implode(" ", $result)))) $valid = TRUE;
    }