I am trying to show images using Slim micro framework v3 without result.
Firstly of all, I am new in Slim so I don't know what is the best pratice to show images using that framework.
So, for now I am trying with this:
$app->get('/images/resources/{resource}', function (Request $request, Response $response, array $args) {
$resource = "./images/resources/".$args['resource'];
$this->logger->info("requested imaged: <".$resource.">");
if(file_exists($resource))
$this->logger->info("image found in <".$resource.">");
else
{
$this->logger->info("image NOT found in <".$resource.">");
return;
}
$image = file_get_contents($resource);
$finfo = new finfo(FILEINFO_MIME_TYPE);
$response->withHeader('Content-Type', 'content-type: ' . $finfo->buffer($image));
echo $image;
});
This works not completely, for example, the loggers report me that all images exist, but in the HTML page I see only PNGs and any SVGs:
The HTML code relative to the screenshot is:
<div class="row text-center" id="downloadApps">
<div class="col-3"><a href="https://www.microsoft.com/store/apps/mybeautifulapp=badge"><img
class="downloadButton"
src="https://assets.windowsphone.com/13484911-a6ab-4170-8b7e-795c1e8b4165/English_get_L_InvariantCulture_Default.png"
alt="Get"/></a></div>
<div class="col-3"><img class="downloadButton" src="/images/resources/google_play_store.png"
alt="Get"/></div>
<div class="col-3"><img class="downloadButton" src="/images/resources/ios_app_store.svg"
alt="Get"/></div>
<div class="col-3"><img class="downloadButton" src="/images/resources/mac_app_store.svg"
alt="Get"/></div>
</div>