PHP [function.require]:无法打开流:没有这样的文件或目录问题
我的一个函数包含以下错误。
require(../htmlpurifier/library/HTMLPurifier.auto.php) [function.require]: failed to open stream: No such file or directory
如果我对路径进行编码,我可以纠正这个问题
./htmlpurifier/library/HTMLPurifier.auto.php
,但是我想在我的网站上的许多不同级别的文件夹中显示包含文件,而不必每次都在我的函数包含内重新编码路径,这违背了我的包含的目的。有没有一种方法可以让我不必每次都重新编码路径来完成这项工作?有没有办法包含完整路径?
I get the following error in one of my function includes.
require(../htmlpurifier/library/HTMLPurifier.auto.php) [function.require]: failed to open stream: No such file or directory
I can correct this problem if I code the path
./htmlpurifier/library/HTMLPurifier.auto.php
But I want to display the include file in many different levels of folders on my website without having to re-code the path inside my function include every time which defeats the purpose of my include. Is there a way I can have this work with out having to re-code the path every time? Is there a way to include the full path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个:
这样你总是包含相对于当前文件路径的文件。
Try this:
That way you always include files relative to the path of the current file.
您使用的路径错误。
只需将这两条线放在一起即可感受差异。
这是两条不同的路径,永远不会同时起作用。后一个指向当前目录,而第一个指向更高一级。
,这是明智的愿望。给你:(
假设这个 htmlpurifier 文件夹位于文档根目录中)
You are using wrong path.
Just put these 2 lines together and feel the difference.
That's 2 different paths and will never work at the same time. Latter one points to the current directory while first one - one level higher.
that's sensible desire. Here you go:
(assuming this htmlpurifier folder lays in the document root)
试试这个
Try this
如何将此 .php 文件的路径配置为脚本中的配置变量?假设您将在所有页面中加载一些通用函数库,因此只需执行以下操作:
在该通用文件中,然后您就可以执行
只要 commonstuff.php 位于 PHP 的 include_path 中的某个位置,那么这样做会更可靠方式而不是尝试在其他地方动态计算路径。特别是如果您的目录结构可能发生变化,导致计算出的路径无效并迫使您再次更改每个 PHP 文件。
How about configuring the path to this .php file as a configuration variable in your script? Presumably you'll be loading some common functions library in all your pages, so just do:
in that common file, then you can just do
As long as commonstuff.php is somewhere in your PHP's include_path, it's far more reliable to do it this way rather than try to dynamically calculate the path everywhere else. Especially if your directory structure might change, rendering the calculated path invalid and forcing you to change every PHP file yet again.