I have gcm in folder (dirC)...here the paths
index.php
dirA/
dirB/
dirC/GCM.php
----/config.php
----/sendMsg.php
dirD/
dirE/dirE1/test.php //send from here
dirF/
gcm.php have code bellow
class GCM {
function __construct() {
}
/**
* Sending Push Notification
*/
public function send_notification($registatoin_ids, $message) {
// include config
include_once './config.php';
//other code here
echo 'test';
}
}
and i successfull send message from sendMsg.php,here the code
include_once './GCM.php';
$message="hello word";
$gcm = new GCM();
$registatoin_ids = array("SEJFOJOEUJFPUWPJR0923740JEU092308UPUPUAUOJLJLJJVPW634");
$message = array($message);
$result = $gcm->send_notification($registatoin_ids, $message);
echo $result;
my question is how to set the path to communicate with GCM.php using include_once from test.php
?
here test.php code
include_once './GCM.php'; //my proble is here ???????????
$message="hello word";
$gcm = new GCM();
$registatoin_ids = array("SEJFOJOEUJFPUWPJR0923740JEU092308UPUPUAUOJLJLJJVPW634");
$message = array($message);
$result = $gcm->send_notification($registatoin_ids, $message);
echo $result;
thanks in advance..
The question is not really clear. But i think the problem is that you make a folder, from which you include and you dont know what folder that is?
For that you have magic constants in php: http://php.net/manual/en/language.constants.predefined.php
When you want to get to your desired directory, you need to use ../, which means 'move one directory up'.
Example: we have a directory structure:
/website
/website/include
/website/template
Imagine we are in /website/template directory. If we want to include /website/include/GCM.php
We can do it with an absolute path, / means the root directory:
include_once '/website/include/GCM.php';
We can do it with a relative path:
include_once '../include/GCM.php';
../ means 'move 1 directory up'.
For more information: http://www.geeksengine.com/article/absolute-relative-path.html
From php documentation you can do something like that :
$path = '/dirC';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
In your index.php (if it's your controller), or in a conf/prepend file, which is included in all your script.
Then a simple include('GCM.php');
will work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.