dousuowu4610
dousuowu4610
2013-11-15 02:27

无法使用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 doudanglang5826 8年前

    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

    点赞 评论 复制链接分享