Cronjob无法使用file_get_contents路径php


Cronjob fails to use file_get_contents path php

我有这个执行的 cronjob /home2/user123/public_html/points/cronjob/lottery.php

彩票.php有使用file_get_contents($_SERVER['DOCUMENT_ROOT'].'/points/lottery/jackpot.txt');的代码

这不起作用,如何编辑文件路径以使其正常工作?如果有帮助,我正在使用 Linux。

假设您的脚本位于

/home2/user123/public_html/points/cronjob/lottery.php

并且您的文本文件位于

/home2/user123/public_html/points/lottery/jackpot.txt

这应该可以完成工作:

$contents = file_get_contents(__DIR__ . '/../lottery/jackpot.txt');