使用 SLIM Framework v3 显示 SVG

Show SVGs using SLIM Framework v3

我正在尝试使用 Slim micro framework v3 显示图像,但没有结果。

首先,我是 Slim 的新手,所以我不知道使用该框架显示图像的最佳实践是什么。

所以,现在我正在尝试这样做:

$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;
});

这并不完全有效,例如,记录器报告我所有图像都存在,但在 HTML 页面中我只看到 PNG 和任何 SVG:

与截图相关的HTML代码为:

<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>

我为我的项目实现了这个功能,并且运行良好。

请检查下面的代码,

$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);
});