我想在 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/