PHP: why do I keep getting an error for the script below?

Posted on 2011-04-28
Last Modified: 2012-05-11
Hello Experts,

I am trying to open xml file... the file is on the server; but having errors when trying to open via script... pls take a look at the script below...

any ideas why is failing?

thank you experts...

if (file_exists('http://localhost/tests/test.xml')) {
    $xml = simplexml_load_file('http://localhost/tests/test.xml');
} else {
    exit('Failed to open test.xml.');

------------- ERROR -------------
Failed to open test.xml

Open in new window

Question by:epifanio67
    LVL 18

    Accepted Solution

    I am assuming when you navigate to http://localhost/tests/test.xml, it show the xml file right?

    Author Comment

    yeah.. i do..

    thank you expert....

    Author Closing Comment

    the path was wrong

    thank you
    LVL 13

    Expert Comment

    Make sure that the permissions are right on both the folder and the file itself to all php to open it.
    LVL 27

    Expert Comment

    by:Lukasz Chmielewski
    Use this syntax:
    if (file_exists($_SERVER['DOCUMENT_ROOT'].'/test/test.xml')) {

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now