php include_once 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5588639/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 21:53:39  来源:igfitidea点击:

php include_once not working

phpinclude

提问by Jean-Philippe Leclerc

What would be the reasons of a non working include_once?

不工作的 include_once 的原因是什么?

Here's my folder hierarchy:

这是我的文件夹层次结构:

/Php/Controls/GridView/GridView.php
/Php/Controls/Form/Form.php

In "Form.php":

在“Form.php”中:

include_once '../GridView/GridView.php';

I'm getting this error:

我收到此错误:

Warning: include_once(../GridView/GridView.php) [function.include-once]: failed to open stream: No such file or directory in ...Form.php on line 4

Warning: include_once() [function.include]: Failed opening '../GridView/GridView.php' for inclusion (include_path='.;C:\php\pear') in ...Form.php on line 4

Please tell me if you want more information.

如果您需要更多信息,请告诉我。

回答by KingCrunch

In Form.phpuse

Form.php使用

include_once dirname(__FILE__) . '/../GridView/GridView.php';

This creates an absolute path, but relative to the file, where its called from.

这将创建一个绝对路径,但相对于调用它的文件。

回答by Tyler Carter

It can't find the file.

它找不到文件。

You should use a full path, like /Php/Controls/GridView/GridView.phpinstead of a relative one.

您应该使用完整路径,/Php/Controls/GridView/GridView.php而不是相对路径。

回答by Richard Rodriguez

Try this:

尝试这个:

include_once './php/Controls/GridView/GridView.php';

回答by Supreme Dolphin

Hope I'm not too late on this one but I thought this might be what you're looking for:

希望我在这方面还不算太晚,但我认为这可能是您要找的:

include_once realpath(dirname(__FILE__)."/../GridView/GridView.php");

Using realpath()allows you to include files even from outside your server document root directory.

使用realpath()允许您包含甚至来自服务器文档根目录之外的文件。