简体   繁体   English

xampp 1.8.1,php 5.4不想包含/需要一个文件

[英]xampp 1.8.1, php 5.4 it doesn't want to include/require a file

I have path like this : "C:/xampp/htdocs/root/my-test/defined-values.php" 我有这样的路径:“ C:/xampp/htdocs/root/my-test/defined-values.php”

that I want to include like this in my index.php 我想这样包含在我的index.php中

if (is_readable($path)) {
    require($path);    
}

and it just simple, it doesn't work. 只是简单,它不起作用。 I have die('test') at the top of defined-values.php file, and it is not being picked at all. 我在define-values.php文件的顶部有die('test'),根本没有被选择。 PHP it doesn't include this file. PHP它不包含此文件。 Require path doesn't return false. 需求路径不会返回false。 So it is working/ 所以它正在工作/

I have setup vhosts, everything, and I'm trying to access index file from url : http://my-test.ttt 我已经安装了虚拟主机,所有东西,我正在尝试从url访问索引文件: http://my-test.ttt

It was working before on older version of xampp, and with php 5.3. 以前在较旧版本的xampp和php 5.3上都可以使用。

What could be the problem? 可能是什么问题呢? Any idea? 任何想法? It is definitely something wrong with PHP.ini file PHP.ini文件肯定有问题

Try using a relative path. 尝试使用相对路径。 It's a better solution, this way you can move your solution to another server without changing the absolute path. 这是一个更好的解决方案,通过这种方式,您可以将解决方案移至另一台服务器,而无需更改绝对路径。

To get the current path use dirname(__FILE__) 要获取当前路径,请使用dirname(__FILE__)
So your code would look like 所以你的代码看起来像

$path = dirname(__FILE__);
require_once($path.'/otherFile.php');

If the file to require was a directory below the current file you can use dirname() again: 如果所需文件是当前文件下的目录,则可以再次使用dirname():

$path = dirname(dirname(__FILE__));

问题是包含路径和简短的打开标记,short_open_tag = On,并且包含路径应​​这样设置:Windows的include_path =“。; C:\\ xampp \\ php \\ PEAR”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM