On Windows XP system, I have test.bat
C:\Path\to\php.exe -f "C:\Path\to\test.php"
I also have test.php
require_once ($_SERVER ['DOCUMENT_ROOT'] . '/Inc/Class/Connect_DB.php');
… more code.
When I execute test.bat on “CMD mode” it returns Fatal error saying it can’t locate the require_once file.
The same file works fine on the browser. It seems that it can’t recognize $_SERVER variable on the bat file. (I plan to run test.bat file via schtasks.exe later on)
Why can’t it read $_SERVER variable here?
Dump $_SERVER and check if document root is set. On my install $_SERVER is available from cli, but the DOCUMENT_ROOT key is set to an empty string. ie -> “”.
You would be better off getting the path by using something in the lines of:
There are many ways of doing this, but that should give you an idea.
Happy coding!