douzhangjian1505 2018-04-17 07:28
浏览 50
已采纳

使用SLIM Framework v3显示SVG

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:

enter image description here

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>
  • 写回答

1条回答 默认 最新

  • douqu8828 2018-04-17 07:34
    关注

    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);
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题