title: DOMDocument save failed to open stream: Permission denied if https
body: <p>I have a problem with saving a file created with DOMDocument.</p>
  
  <p>My host has active an HTTPS protocol, to make sure that all pages use this protocol I created the following htaccess:</p>
  
  <pre><code>RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  </code></pre>
  
  <p>And all pages are correctly redirected to the HTTPS protocol.</p>
  
  <p>The problem occurs when, after creating the DOMDocument, I save it.</p>
  
  <p>If I remove .htaccess the file is saved correctly, if instead I open the page that is currently creating the file with the https protocol the file is not created and I get this error:</p>
  
  <blockquote>
    <p>Warning: DOMDocument::save(../../data/files/1/TEST.xml): failed to open stream: Permission denied in /usr/local/psa/home/vhosts/myhost.com/httpdocs/user/test/dir/dirtwo/dirthree/test.php on line 1229 2</p>
  </blockquote>
  
  <p>The path where I'm trying to save the file is like 755 permissions.</p>
  
  <p>I repeat in HTTP it works perfectly, the file is created and saved correctly. As soon as I force all in HTTPS the file is not saved.</p>
  
  <p>Does anyone know where I'm wrong?</p>
  
  <p><strong>SCRIPT</strong></p>
  
  <pre><code>&lt;?php
  echo "start&lt;br&gt;";
  ini_set('display_errors', 1);
  ini_set('display_startup_errors', 1);
  error_reporting(E_ALL);
  
  $doc = new DOMDocument('1.0');
  // nous voulons un bel affichage
  $doc-&gt;formatOutput = true;
  
  $root = $doc-&gt;createElement('book');
  $root = $doc-&gt;appendChild($root);
  
  $title = $doc-&gt;createElement('title');
  $title = $root-&gt;appendChild($title);
  
  $text = $doc-&gt;createTextNode('This is the title');
  $text = $title-&gt;appendChild($text);
  
  $doc-&gt;save("test.xml");
  echo "&lt;br&gt;end";
  ?&gt;
  </code></pre>
  
  <p><strong>RESULT</strong></p>
  
  <pre><code>start
  Warning: DOMDocument::save(test.xml): failed to open stream: Permission denied in /usr/local/psa/home/vhosts/myhost.com/httpdocs/user/test/dir/dirtwo/dirthree/test.php on line 20
  end
  </code></pre>
  
  <p>Thank you!</p>