简体   繁体   中英

Show SVGs using SLIM Framework v3

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>

I implemented this functionality for my project and it's working fine.

Please check the code below,

$app->get('/image/p/{data:\w+}', function($request, $response, $args) {
$data = $args['data'];
$image = @file_get_contents("http://localhost/main/media/image/p/$data");
if($image === FALSE) {
    $handler = $this->notFoundHandler;
    return $handler($request, $response);    
}

$response->write($image);
return $response->withHeader('Content-Type', FILEINFO_MIME_TYPE);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM