I have the following code that determines if an image is an SVG or not so that it displays the source if it is (the SVG can then be coloured using CSS):
if (strpos('url_to_an_image', '.svg') !== false) {
echo file_get_contents('url_to_an_image');
} else {
echo '<img src="url_to_an_image" />';
}
This worked fine, until I added an IP restriction in htaccess when I get the following error:
file_get_contents(http://example.com/images/icons/icon-email.svg): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden
I have tried the solutions that suggest spoofing a real browser request; they don't work.
Is there another solution for this, or another approach I could use to display SVGs?