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
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');

Link to comment
Share on other sites

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');

Link to comment
Share on other sites

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');

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.