dousuowu4610 2013-11-15 02:27
浏览 85
已采纳

无法使用simplexml_load_file上传目录

So I am not exactly sure why my code doesn't work, but here is the error I get:

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

Here is the code I use:

<?php 

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

?>

I am trying to go up two directories where the "settings.xml" file is at. Am I am doing this the right way or is there another way to do this?

  • 写回答

1条回答 默认 最新

  • doudanglang5826 2013-11-15 02:29
    关注

    Try this

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

    Always keep in mine that . (the CWD) is the directory of the PHP script at the root of any include / require tree and only then if your configured include_path actually includes . (which it does by default though this can be changed in code).

    If your home.php script is included by another script in a different directory, . is relative to that other script.

    Using __DIR__ makes sure you're always starting at the parent directory of the current script.

    See http://php.net/manual/language.constants.predefined.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题