Relative path not working in cron PHP script

前端 未结 8 1539
甜味超标
甜味超标 2020-11-28 07:59

If a PHP script is run as a cron script, the includes often fail if relative paths are used. For example, if you have

require_once(\'foo.php\');
8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 08:27

    Change the working directory to the running file path. Just use

    chdir(dirname(__FILE__));
    include_once '../your_file_name.php'; //we can use relative path after changing directory
    

    in the running file. Then you won't need to change all the relative paths to absolute paths in every page.

提交回复
热议问题