简体   繁体   中英

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 :

    @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.

似乎您需要提供可写路径来保存方法,例如$dom->save(storage_path('result.xml'))

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM