Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

uccdev's avatar

simplexml_load_file() makes I/O warning in Laravel view?

So I have a simple cdcatalog.blade.php view file:

   <?php
     $file = simplexml_load_file('note.xml');
     print_r($file);
   ?>

And note.xml looks like this:

   <?xml version="1.0" encoding="UTF-8"?>
   <note>
          <to>Tove</to>
          <from>Jani</from>
          <heading>Reminder</heading>
          <body>Don't forget me this weekend!</body>
   </note>

However, when I call it, I get this error: simplexml_load_file(): I/O warning : failed to load external entity &quot;note.xml&quot; (View: /home/vagrant/bitbucket/myProject/resources/views/cdcatalog.blade.php)

Both files are in the same folder (for now, for testing purposes), so I'm wondering why this doesn't work? Does anyone have any experience or understanding of this? Any help would be greatly appreciated

0 likes
2 replies
click's avatar
click
Best Answer
Level 35

First of all, you should not do these kind of things in your template files. You should do this in your controller and pass the content of note.xml (or whatever you want to do with it) to your view.

But to answer your question. You can't use only a filename when using file methods like this. You should always use absolute paths when working with native file functions.

So for example simplexml_load_file(resource_path('/views/note.xml')); See https://laravel.com/docs/5.8/helpers#method-resource-path for what resource_path() does, there are more methods similar like this.

1 like

Please or to participate in this conversation.