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 :
@php $dom = new DOMDocument('1.0','UTF-8'); $dom->formatOutput = true; $root = $dom->createElement('student'); $dom->appendChild($root); $result = $dom->createElement('result'); $root->appendChild($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'); @endphp
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.
Advertisement
Answer
Seems you need to provide writeble path to save method, like
$dom->save(storage_path('result.xml'))