选择在require语句正确的道路 [英] Choosing the right path in a require statement

查看:108
本文介绍了选择在require语句正确的道路的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将一个产生一个成功的 PHP 需要声明的路径,如果要连接的两个文件有不同的目录?我希望能够对能够在另一个使用所有的数据的一个文件中。我想包括文件/需要位于桌面> pushchatserver> API> api.php 。当设置本地服务器,我不得不放pushchatservers内容的路径在应用程序/ MAMP / conf目录/阿帕奇/ httpd.conf文件文件中像这样使服务器可以达到它。
 

How would one generate a successful php require statement path if the two files being joined have different directories? I want to be able to be able to use all of the data in one file in another. The file I want to include/require is located in desktop > pushchatserver > api > api.php. When setting up the local server I had to put the paths of pushchatservers contents in the Applications/MAMP/conf/apache/httpd.conf file like this so the server could reach it.

 //This will be the require statement located in the php file that wants to use the data from api.php

require("/What/should/the/path/be?/api.php");

另外,如果有帮助,这是该应用程序用于通信与pushchatserver的内容在运行时的#define ServerApiURL @http://192.168.1.5:44447/api.php的网址我的问题:请问该URL的工作作为一个路径?似乎有很多不同的选择。有谁知道哪条路径会成功这一类需要声明?

Also, if it helps, this is the url that the app uses to communicate with pushchatserver's contents at run-time #define ServerApiURL @"http://192.168.1.5:44447/api.php" My question : Would that url work as a path? There seem to be a lot of different options. Does anyone know which path will be successful for this type of require statement?

推荐答案

的要求路径总是相对于在include_path ini文件设置中定义的目录列表。因此,你通常不会有一个完整的路径,而是从include_path中值的相对路径结束。请注意,您可以在httpd.conf文件中设置PHP中的include_path设置,如果你喜欢类似于你在你的例子中的php_flag设置做了什么。

The require path is always relative to the list of directories defined in the include_path ini file setting. Hence you would not usually end up with a full path but rather a relative path from the include_path value. Note that you can set the include_path setting in PHP from within the httpd.conf file if you like similarly to what you have done with the php_flag setting in your example.

我几乎不能读你的屏幕截图,但我认为,填鸭式的答案是:

I can barely read your screen shot but I think the spoon-feeding answer is:

这行添加到您的Apache配置:

add this line to your apache config:

php_value "include_path"  "/Users/ratthijs/Desktop/PushChatServer/api"

然后你可以只说:

And then you could just say:

require_once('api.php');

这篇关于选择在require语句正确的道路的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆