Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SambhavP's avatar

Including SVG code contents in Laravel Blade Template

I have this application where svg files uploaded in my storage folder. I want to include the code contents of svg file inside my blade template. So far, I've tried multiple methods with the same result, a timeout exception.

I've tried using the file_get_contents method

{!! file_get_contents($url) !!}

or using the dom document object:

$svg = new \DOMDocument();
$svg->load($url);
$output = $svg->saveXML($svg->documentElement);

or using the cURL operation:

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);

$data = curl_exec($ch);
curl_close($ch);
return $data;

or the Laravel HTTP Client (which probably uses the cURL operation anyway):

$response = Http::get($url);
return $response->body();

all of which resulted in the same timeout. Here's a snippet of the exception while using the HTTP client:

cURL error 28: Operation timed out after 30001 milliseconds with 0 bytes received (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)

I also tried increasing the max_execution_time in my PHP configuration file but it still didn't work. I've been stuck for a couple of days now and I'm out of ideas. When I go to the url on my browser, the SVG file loads just fine. So please, any help is appreciated.

0 likes
2 replies

Please or to participate in this conversation.