我在windows 7中使用wampserver(本地)。我收到这个警告信息:
Warning: include(): Failed opening 'DateUtility' for inclusion
(include_path='.;C:'php'pear') in C:'wamp'www'dwwithphp'_includes'footer.php on line 1.
在phpinfo中,我验证了以下内容:
Configuration File (php.ini) Path C:'Windows
Loaded Configuration File C:'wamp'bin'apache'apache2.4.9'bin'php.ini
and the include_path line is located in C:'wamp'bin'php5.5.12'phpini
并且仍然…在文件夹CCD_ 1中我有3个CCD_,phpini、phpini开发和phpini_production。它们在路径和目录中都有相同的信息。我不知道如何构建include_path,path1和path2是什么。在中
include_path = ".;c:'php'includes"
以下是一些详细信息:有问题的文件是DateUtility.php
<?php
class DateUtility {
public function getcurrenttime() {
date_default_timezone_set("America/New_York");
echo "The current time is: " ;
echo date("g:i a");
}
}
?>
我正试图将其包含在footer.php文件的第一行中。
<?php include("DateUtility"); ?>
两个文件都在_includes文件夹中
_includes
header.php
footer.php
DateUtility.php
正如你所能想象的那样,他们遵循琳达的在线课程
感谢帮助完成include_pathDov
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;
; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "'path1;'path2"
;include_path = ".;c:'php'includes"
;
; PHP's default setting for include_path is ".;/path/to/php/pear"
; http://php.net/include-path
如果您提供了要包含的文件的路径,就不必麻烦处理php配置文件(.ini)。
首先需要包含该文件,然后在DateUtility类中运行该方法。
更改此项:
<?php include("DateUtility"); ?>
到此:
<?php
// first include the file so the code is available using the full file name.
// because the files are in the same directory you shouldn't need a path
include("DateUtility.php");
// run the method inside the DateUtility class
DateUtility::getcurrenttime();
?>
为了回答您关于配置的问题,路径1和路径2只是示例。因为这些行以";"开头,所以它们是突出的,根本不会影响您的配置。注释显示,如果这是一个unix系统,您可以添加由":"分隔的路径,如果是一个windows系统,请使用";"
; Windows: "'path1;'path2"
;include_path = ".;c:'php'includes"
已被注释掉。如果你想添加新的路径,你会把它改为:
; Windows: "'path1;'path2"
include_path = ".;c:'path'to'your'folder"
但正如我所说,如果您在include()函数中提供了正确的路径,则不需要这样做。