更改 include_path 或在每个 php 文件前面添加
我有一个应用程序,它将一些数据存储在 /library/
目录中的 .php
文件中, 例如。 /library/config.php
。
在我的旧主机上,library
位于包含路径中,因此我可以在任何地方执行 require('config.php')
而无需提供真实路径。
是否有机会自动添加每个 .php 文件以更新包含路径?
有一些情况:
- 应用程序不遵循前端控制器模式
- 我无法访问
php.ini
- 我无法直接访问
include_path
中已存在的任何目录 - I无法使用
php_flag include_path
- 我无法使用
php_flag auto_prepend_file
- 一些 .php 文件在
.htaccess
中有自己的规则
除了 < code>ctrl+H 并将 替换为
?
编辑:
我正在寻找类似于:
RewriteCond %{REQUEST_FILENAME} !-F
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (^*\.php)$ /library/$1 [NC,L]
I have an app which stores some data in .php
files in /library/
directory,
eg. /library/config.php
.
On my old hosting library
was in the include path, so I was able do do require('config.php')
anywhere without providing the real path.
Is there any chance to auto prepend each .php file, to update the include path?
There are some circumstances:
- the app does not follow front controller pattern
- I have no access to
php.ini
- I have no direct access to any of the dirs already present in
include_path
- I can't use
php_flag include_path
- I can't use
php_flag auto_prepend_file
- some .php files have their own rules in
.htaccess
Any other way than ctrl+H
and replace <?
with <? set_include_path…
?
Edit:
What I am looking for would be something similar to:
RewriteCond %{REQUEST_FILENAME} !-F
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (^*\.php)$ /library/$1 [NC,L]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在需要调整库文件的文件顶部添加
set_include_path()
运行时的包含路径(无需触及 php.ini 或 .htaccess 文件)。这会将您的库路径添加到当前包含路径之前,并使那里的文件直接可用。您需要调整
'/library'
以匹配您的库路径(相对于当前文件的位置)。Add
set_include_path()
at the top of the file where you need the library files to adjust the include path at runtime (no need to touchphp.ini
or.htaccess
files).This prepends your library path to the current include path and makes the files there directly available. You need to adjust
'/library'
to match your library path (relative to the current file's location).ini_set()
也被禁止吗?这也允许您修改include_path
。Is
ini_set()
forbidden too? Which allows you to modify theinclude_path
too.