【问题标题】:Laravel Glide not finding images at urls with extensionLaravel Glide 没有在带有扩展名的 url 上找到图像
【发布时间】:2019-03-24 22:51:17
【问题描述】:

我正在使用 Glide,并关注了这个视频 https://vimeo.com/118089742 这基本上是一个演练 官方网站上的说明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 的图像(但是,原始图像确实出现了)。

我发现如果我将路由切换到以下路径,并且只转到 url.com/img/test?h=100(没有扩展名), 然后我得到了我想要的 Glided 图像:

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

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

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,又失败了。

您是否发现我正在做的事情有什么问题,或者是否有解释为什么我不能直接转到图像 路径(带有扩展名)?

【问题讨论】:

    标签: laravel image-manipulation php-glide


    【解决方案1】:

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

    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)$.

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

    【讨论】:

      【解决方案2】:

      这都是一个缓存问题。在使用 Glide 之前不要通过 htaccess 或 nginx 缓存你的图片。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-25
      • 2012-08-12
      • 1970-01-01
      • 2010-12-22
      • 1970-01-01
      相关资源
      最近更新 更多