Home > other >  Laravel DOMDocument : failed to open stream: Permission denied
Laravel DOMDocument : failed to open stream: Permission denied

Time:10-20

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.

CodePudding user response:

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

CodePudding user response:

In which directory/Folder you create "result.xml" file, that directory you should give 775 permission

then run below command

php artisan optimize:clear

OR

php artisan config:clear
  • Related