Php:包含文件本地主机和服务器:不同的路径
让我们想象一下这种情况:你的开发者目录是这样的:
- 项目 A
- 项目 B
- 项目 C
- 公共项
“公共项”是项目中常用的公共文件、类、函数。所以在项目“X”中:
require_once '../commonitems/mysqlDate.php';
等等。公共项目不能多次复制到每个项目。 但是当你需要将所有这些上传到目录时,就不能这样了。一个远程网站结构是:
- css
- js
- 设计
- 常用
- 代码
- 代码/通用
因此没有外部“常见项目”目录。如何用“优雅”的方式包含本地主机和远程站点上不同的文件?我是否应该设置“if SERVERNAME == localhost then include X else include Y”看起来很愚蠢:Pthanx
提前
let's imagine this situation: your developer directory is something like this:
- project A
- project B
- project C
- common items
the "common items" are common files, classes, functions which are to be used commonly in your project. So in project "X":
require_once '../commonitems/mysqlDate.php';
and so on. Common items cant be copied multiple times to each projects.
But when you need to upload all of this to directory, it cant be like that. A remote website structure is:
- css
- js
- design
- common
- code
- code/common
so no outside "common items" directory. How to say "elegant" way to include files different on localhost and remote site? Should I set up "if SERVERNAME == localhost then include X else include Y" looks silly :P
thanx in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
PHP include_path 并将其设置为开发环境中的正确目录。
Use
and set the PHP include_path to the correct directory on your development environment.