我将此代码放入函数(php 类)中:
$theFile = '/test/test.xml'; // these are in the public folder
dd(file_get_contents($theFile));
如果我去mydomain.local/test/test.xml
,我得到了有效的 xml 代码。
但与file_get_contents
,我收到此错误:
file_get_contents(/test/test.xml): failed to open stream: No such file or directory
如何解决这个问题?
流明没有public_path()
您可能在 Laravel 中熟悉它,可以轻松获取公共文件的路径。
重新实现它的最简单方法是添加一个名为的包伊拉扎赛德/larasupport https://github.com/irazasyed/larasupport到您的项目中添加各种缺失的助手(包括public_path()
)以及添加 Lumen 中缺少的供应商发布命令。
或者,如果您不想添加第三方包,只需在您的应用程序目录中创建一个名为的文件helpers.php
然后在你的composer.json
文件在“autoload”部分添加以下内容并运行composer dump-autoload
刷新自动加载器缓存:
"files": [
"app/helpers.php"
],
然后内helpers.php
添加以下内容:
<?php
if (!function_exists('public_path')) {
/**
* Get the path to the public folder.
*
* @param string $path
* @return string
*/
function public_path($path = '')
{
return env('PUBLIC_PATH', base_path('public')) . ($path ? '/' . $path : $path);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)