【问题标题】:Laravel: load images stored indise 'storage' folderLaravel:加载存储在“存储”文件夹中的图像
【发布时间】:2016-12-19 01:54:13
【问题描述】:

我正在尝试显示存储在“存储”文件夹中的图像,以保护图像文件夹。我应该如何处理 2 个参数,下面的代码效果不佳:

路线:

Route::get('img/users/{id}/logo/{image}', function($id = null, $image = null)
{
    $path = storage_path().'/img/profils/'.$id.'/logo/'.$image;
    if (file_exists($path)) { 
        return Response::download($path);
    } 
});

查看:

src="{!!asset('img/users/'.$user->id.'/logo/'.$user->imagelogo)!!}"

【问题讨论】:

  • 发布错误
  • 怎么,没看懂?
  • 我无法通过配置文件获取图像,但如果我这样做,请设置用户的 id,它会显示图像配置文件:Route::get('img/users/2/logo/ {image}', function($id = null, $image = null) { $path = storage_path().'/img/profils/2/logo/'.$image;

标签: php mysql image laravel


【解决方案1】:

我已经这样做了,但没有使用你的方式。我所做的是,
将图像保存在public 文件夹中。
然后创建一个自定义的css 并使用

.your div tag id {
width: 100%; //px you need
height: auto;
padding: 100px 0;
text-align: center;
color: #fff;
background: url(../your image.jpg);
background-color: #000;
 }

我认为在<panel> 中使用它会给你一个解决方案。

【讨论】:

  • 拜托,你能给我更多的解释吗?
  • 你需要在哪里发布这张图片?侧边栏或类似的东西?
  • 我要保护文件夹中的所有图片。
  • 我不知道您为什么要使用Route::get 方法来执行此操作。
  • 您还有其他解决方案吗?
猜你喜欢
  • 2016-09-01
  • 2014-02-03
  • 2019-11-16
  • 2017-09-03
  • 2012-11-17
  • 1970-01-01
  • 1970-01-01
  • 2020-12-19
  • 1970-01-01
相关资源
最近更新 更多