Jason Miesionczek
Jason Miesionczek

Reputation: 14448

Loading file from the same directory doesn't work unless I specify the full path

So I have this line of code inside a WordPress plugin. The code file is in the same folder as the XML file I'm trying to load. When I remove the full path and leave just the filename I get an I/O error.

$dom->load("/home/tapadmin/public_html/demo10/wp-content/plugins/".
    "agentmanager/fielddefs.xml");

What's the correct way to load the XML file so I don't have to specify the full path?

Upvotes: 2

Views: 579

Answers (1)

Artefacto
Artefacto

Reputation: 97815

The relative paths you specify should be relative to the directory of the originally called PHP file, not the one in which you're doing the include.

So, if a page requests /a/index.php and that includes /a/b/inc.php.inc, a relative path in inc.php.inc will be relative to /a/, not /a/b/.

Consider using dirname(__FILE__) instead to get the directory of the current file.

If the extension properly respects the virtual directory.

Upvotes: 7

Related Questions