[英]PHP script (include) not working from command line
I have a php script that works perfectly fine when run by the web server but when I run the script from the command line (or as a cron job) then it fails to find the file. 我有一个PHP脚本,当由Web服务器运行时完全正常,但是当我从命令行(或作为cron作业)运行脚本时,它无法找到该文件。 The code that errors out is:
出错的代码是:
include('fpdf181/fpdf.php');
I tried including DIR but that does not work either 我试过包括DIR,但这也不起作用
include(__DIR__ .'fpdf181/fpdf.php');
Can someone tell me how to include files for a script that will run from the command line 有人可以告诉我如何包含将从命令行运行的脚本的文件
can you see this ( PHP Cron Job: Including file not working? ) 你能看到这个( PHP Cron Job:包括文件不工作吗? )
as the link, you use "require" and not include 作为链接,您使用“require”而不包括
Code: require('./fpdf181/fpdf.php') 代码:require('./ fpdf181 / fpdf.php')
happy codeing. 快乐的编码。
您可以使用文件的完整路径(独立于当前目录/ env)。
include('/path/to/lib/fpdf181/fpdf.php');
我能够通过在目录上执行cwd并转到放置脚本的文件夹来执行我的脚本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.