“(include_path ='.:/usr/share/pear:/usr/share/php')"是什么意思? [英] what does it mean "(include_path='.:/usr/share/pear:/usr/share/php')"?

查看:295
本文介绍了“(include_path ='.:/usr/share/pear:/usr/share/php')"是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在EC2上具有文件结构,例如:,但是遇到了一些文件引用问题.

I have file structure on EC2 like : but facing some file referencing problem.

index.php
-db
  -config.php
-cron
  -cron1.php

我尝试将文件引用为:

`require_once (dirname(__FILE__).'/db/config.php');`
`require_once (($_SERVER['DOCUMENT_ROOT']).'/db/config.php');`

但是cron无法运行.它在邮件中显示为

but cron doesn't run.it gives error in mail as

`PHP Warning:  require_once(/db/config.php): failed to open stream: No such file or directory in /var/www/html/cron/cron1.php on line 3

Warning: require_once(/db/config.php): failed to open stream: No such file or directory in /var/www/html/cron/cron1.php on line 3

PHP Fatal error:  require_once(): Failed opening required '/db/config.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/cron/cron1.php on line 3

Fatal error: require_once(): Failed opening required '/db/config.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/cron/cron1.php on line 3`

推荐答案

如果您查看PHP常量 PATH_SEPARATOR ,您会看到它是:".

If you look at the PHP constant PATH_SEPARATOR, you will see it being ":" for you.

如果使用该字符将字符串.:/usr/share/pear:/usr/share/php"分开,则会得到3个部分

If you break apart your string ".:/usr/share/pear:/usr/share/php" using that character, you will get 3 parts

  • . (这表示您的代码所在的当前目录)
  • /usr/share/pear
  • /usr/share/ph

任何试图包含()/需要()的东西,都会以这种顺序在这些目录中查找.

Any attempts to include()/require() things, will look in these directories, in this order.

它向您显示错误消息中告诉您在哪里找不到您想要的文件()

It is showing you that in the error message to let you know where it could NOT find the file you were trying to require()

对于您的第一个要求,如果您的index.php中包含该内容,那么您就不需要dir目录,只需执行以下操作即可:

For your first require, if that is being included from your index.php, then you dont need the dir stuff, just do:

require_once ( 'db/config.php');

这篇关于“(include_path ='.:/usr/share/pear:/usr/share/php')"是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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