Laravel Glide无法在带有扩展名的网址中找到图像 [英] Laravel Glide not finding images at urls with extension

查看:116
本文介绍了Laravel Glide无法在带有扩展名的网址中找到图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Glide,并按照以下视频 https://vimeo.com/118089742 演练 有关官方网站 http://glide.thephpleague.com/

I am using Glide, and followed this video https://vimeo.com/118089742 which basically is a walk-through for the instructions on the official site http://glide.thephpleague.com/

这是我的服务提供商:

$this->app->singleton('League\Glide\Server', function ($app) {

        return \League\Glide\ServerFactory::create([
                'source' => public_path(),
                'cache' => public_path(),
                'source_path_prefix' => 'images/uploads',
                'cache_path_prefix' => 'images/cache',
                'base_url' => '/img/',
        ]);
    });

这是我当前的路线:

Route::get('img/{path}', function (League\Glide\Server $server, Illuminate\Http\Request $request) {
    $server->outputImage($request);
});

但是我遇到了问题.当我转到url.com/img/test.png?h=100时,它不起作用.看铬时 页面上的开发工具,我得到的图像是404(但是,原始图像确实出现了).

But I am running into problems. When I go to url.com/img/test.png?h=100, it does not work. When looking at chrome dev tools on the page, I get a 404 for the image (however, the original image DOES appear).

我发现,如果我将路线切换到以下位置,并且仅转到url.com/img/test?h=100(不带扩展名), 然后我得到了想要的Glided图片:

I have found that if I switch my route to the following, and only go to url.com/img/test?h=100 (without the extension), then I get the Glided image that I want:

 Route::get('img/{path}', function (League\Glide\Server $server,  Illuminate\Http\Request $request) {
    $server->outputImage($request->path() . '.png', $request->all());
});

但是,如果我删除扩展名的串联并简单地使用:

However, if I remove the concatenation of the extension and go with simply:

Route::get('img/{path}', function (League\Glide\Server $server,  Illuminate\Http\Request $request) {
    $server->outputImage($request->path(), $request->all());
});

然后路由回到url.com/img/test.png?h=100,它再次失败.

Then route back to url.com/img/test.png?h=100, it fails again.

您看到我的操作有什么问题吗,还是有关于为什么我不能直接进入图像的解释? 路径(带有扩展名)?

Do you see anything wrong with what I'm doing, or is there an explanation for why I can't go directly to the image path (with the extension)?

推荐答案

我遇到了同样的问题,并尝试了很多方法.所有以/img/开头的url都是Glide生成的图像. /assets/中的所有都是静态文件. 我已经放弃并更改了

I'm having the same problem and tried many things. All url's starting with /img/ are Glide generated images. All in /assets/ are static files. I've given up and changed

location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$

location ~* ^/assets/.*\.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$.

希望有人对此有一个好的解决方案!

Hopefully someone has a good solution for this!

这篇关于Laravel Glide无法在带有扩展名的网址中找到图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆