I use $_SERVER[\'DOCUMENT_ROOT\'].\"/lib/sft_required.php\"; to include the \'sft_required\' file in a PHP script. When I run this file using browser, it works fine but whe
In my case, this issue was caused by the $_SERVER['DOCUMENT_ROOT'] path having a trailing slash during normal site operations and no trailing slash during cron jobs.
I'm not sure what was causing that to happen, but as a workaround, I switched my code to use ABSPATH instead, since it appeared to be returning a consistent value.
So, in other words, I changed this:
$private_folder = realpath($_SERVER['DOCUMENT_ROOT'] . "../private_html");
to this:
$private_folder = realpath(ABSPATH . "../private_html");
There are several other solutions to that problem as well, such as using str_replace or rtrim.