gpt4 book ai didi

php - 流明 : How to display the image on a public folder?

转载 作者:行者123 更新时间:2023-12-05 04:12:39 28 4
gpt4 key购买 nike

我想在 Lumen 项目中显示存储在 public 文件夹中的图像。但是当我试图在浏览器中显示它时,我得到了 404 not found。

我已经创建了 Assets url 助手:

if (!function_exists('urlGenerator')) {
/**
* @return \Laravel\Lumen\Routing\UrlGenerator
*/
function urlGenerator() {
return new \Laravel\Lumen\Routing\UrlGenerator(app());
}
}

if (!function_exists('asset')) {
/**
* @param $path
* @param bool $secured
*
* @return string
*/
function asset($path, $secured = false) {
return urlGenerator()->asset($path, $secured);
}
}

这就是我调用图片 URL 的方式:

asset('public/uploads/images/product/') . $product->image

为什么当我尝试调用公用文件夹中的图像时 lumen 指的是路由?

最佳答案

你可以像下面那样做。

asset('uploads/images/product/' . $product->image)

asset('uploads/images/product/') . '/' . $product->image

关于php - 流明 : How to display the image on a public folder?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40121725/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com