include():无法打开'DateUtility'以包含

时间:2014-09-03 22:12:43

标签: php apache

我在Windows 7中使用wampserver(local)。 我收到此警告信息:

Warning: include(): Failed opening 'DateUtility' for inclusion
(include_path='.;C:\php\pear') in C:\wamp\www\dwwithphp\_includes\footer.php on line 1.

在Φhephpinfo中,我验证了以下内容:

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  

仍然......在c:\wamp\bin\php5.5.12文件夹中我有3个phpini个文件, phpini,phpini-development和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

正如你可以从Lynda的在线课程中看到的那样。

感谢帮助完成include_path  多夫

;;;;;;;;;;;;;;;;;;;;;;;;;
; 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

1 个答案:

答案 0 :(得分:1)

如果您提供要尝试包含的文件的路径,则不必乱用您的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();
?>

要回答关于配置的问题,path1和path2仅是示例。因为这些行以“;”开头它们被注释掉了,根本不会影响您的配置。评论显示,如果这是一个unix系统,你添加用“:”分隔的路径,如果是windows系统使用“;”

; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"

被注释掉了。如果你想添加一条新路径,你可以改为:

; Windows: "\path1;\path2"
include_path = ".;c:\path\to\your\folder"

但正如我所说,如果你在include()函数中提供正确的路径,则不需要这样做。

相关问题