PHP CLI include()找不到文件 [英] PHP CLI include() isn't finding the file

查看:306
本文介绍了PHP CLI include()找不到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文件结构如下:

config.php
script
|--myscript.php

myscript.php

myscript.php

<?php
require '../config.php';
?>

执行php /path/to/myscript.php时得到Warning: require(../config.php): failed to open stream: No such file or directory.

原因是什么?

推荐答案

这是因为当前工作目录是您在其中调用命令的目录,而不是脚本所在的目录.

That's because your current working directory is the one you call your command at, not the one your script is located in.

使用

require __DIR__ . '/../config.php';

相反. __DIR__是指向当前文件所在目录的const.

instead. __DIR__ is a const that points to the directory current file is located in.

这篇关于PHP CLI include()找不到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆