Jump to content

simplexml_load_file syntax


jbooth952

Recommended Posts

Does the file have to be in the document root?

 

If not, what is the correct syntax to point simplexml_load_file() to a directory on the server that is not the document root?

 

ie what goes between the ()

 

this works fine if the .xml file is in my public html root - simplexml_load_file('sample.xml')

 

but when I put the file in a different directory on the server, I can't figure out how to point to it.

 

Help is appreciated.

Link to comment
https://forums.phpfreaks.com/topic/219218-simplexml_load_file-syntax/
Share on other sites

What is the path to the file?  If it's outside of the doroot (not a subdir in docroot) you put that full path:

 

/path/to/file/sample.xml

 

If it's in a subdir of the docroot then you can use the full path or a relative one like (if it is in the docroot/files/xml dir):

 

files/xml/sample.xml

 

Also, add this to show errors in case there are permission issues, etc...

error_reporting(E_ALL);
ini_set('display_errors', '1');

Thanks. I pointed to the full path name in the script like this;

simplexml_load_file('/home/userid/xmldata/sampleXML.xml');

and when I run the script from my production root, it works fine.

 

For testing I put my scripts in a sub directory of public_html (my root)

 

when I run the script from there, it can't find the file. Do I have to change simplexml_load_file('/home/ezsched/xmldata/assignXML.xml'); when I'm running from the test directory?

 

What is the path to the file?  If it's outside of the doroot (not a subdir in docroot) you put that full path:

 

/path/to/file/sample.xml

 

If it's in a subdir of the docroot then you can use the full path or a relative one like (if it is in the docroot/files/xml dir):

 

files/xml/sample.xml

 

Also, add this to show errors in case there are permission issues, etc...

error_reporting(E_ALL);
ini_set('display_errors', '1');

Disregard the last post, I got it working. It finds the file from both the prod and test area using the same path parm.

 

Thanks for your help.

 

Thanks. I pointed to the full path name in the script like this;

simplexml_load_file('/home/userid/xmldata/sampleXML.xml');

and when I run the script from my production root, it works fine.

 

For testing I put my scripts in a sub directory of public_html (my root)

 

when I run the script from there, it can't find the file. Do I have to change simplexml_load_file('/home/ezsched/xmldata/assignXML.xml'); when I'm running from the test directory?

 

What is the path to the file?  If it's outside of the doroot (not a subdir in docroot) you put that full path:

 

/path/to/file/sample.xml

 

If it's in a subdir of the docroot then you can use the full path or a relative one like (if it is in the docroot/files/xml dir):

 

files/xml/sample.xml

 

Also, add this to show errors in case there are permission issues, etc...

error_reporting(E_ALL);
ini_set('display_errors', '1');

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.