Skip to content

Laravel DOMDocument : failed to open stream: Permission denied

I’m trying to generate xml file in Laravel, I use DOMdocument but I got this error message when I try to save the file :

DOMDocument::save(result.xml): failed to open stream: Permission denied (View: /opt/lampp/htdocs/myproj/resources/views/feed/index.blade.php)

Code in blade file :

$dom = new DOMDocument('1.0','UTF-8');
  $dom->formatOutput = true;

  $root = $dom->createElement('student');

  $result = $dom->createElement('result');

  $result->setAttribute('id', 1);
  $result->appendChild( $dom->createElement('name', 'Opal Kole') );
  $result->appendChild( $dom->createElement('sgpa', '8.1') );
  $result->appendChild( $dom->createElement('cgpa', '8.4') );

  echo '<xmp>'. $dom->saveXML() .'</xmp>';
  $dom->save('result.xml') or die('XML Create Error');

I know it’s something with permission but i’m not sure where to change the permission and for what. Thank you for help in advance.



Seems you need to provide writeble path to save method, like $dom->save(storage_path('result.xml'))