编程语言
首页 > 编程语言> > php-无法使用simplexml_load_file进入目录

php-无法使用simplexml_load_file进入目录

作者:互联网

所以我不确定为什么我的代码不起作用,但是这是我得到的错误:

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "../../setting.xml" in /home1/sk8ermid/public_html/MVP/themes/SDS-2013/home.php on line 3

这是我使用的代码:

<?php 

$settings = simplexml_load_file('../../setting.xml');
$site_title = $settings->title;

?>

我正在尝试查找“ settings.xml”文件所在的两个目录.我是在以正确的方式执行此操作,还是有另一种方式来执行此操作?

解决方法:

尝试这个

$settings = simplexml_load_file(__DIR__ . '/../../setting.xml');

永远保持在我的那个. (CWD)是PHP脚本的目录,该目录位于任何include / require树的根目录,并且仅在您配置的include_path实际上包含时才如此. (尽管可以在代码中更改,但默认情况下会这样做).

如果您的home.php脚本包含在其他目录中的另一个脚本中,则.相对于其他脚本.

使用__DIR__确保您始终从当前脚本的父目录开始.

查看http://php.net/manual/language.constants.predefined.php

标签:simplexml,php
来源: https://codeday.me/bug/20191122/2060206.html