1

I have a problem with saving a file created with DOMDocument.

My host has active an HTTPS protocol, to make sure that all pages use this protocol I created the following htaccess:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

And all pages are correctly redirected to the HTTPS protocol.

The problem occurs when, after creating the DOMDocument, I save it.

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:

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

The path where I'm trying to save the file is like 755 permissions.

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.

Does anyone know where I'm wrong?

SCRIPT

<?php
echo "start<br>";
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->formatOutput = true;

$root = $doc->createElement('book');
$root = $doc->appendChild($root);

$title = $doc->createElement('title');
$title = $root->appendChild($title);

$text = $doc->createTextNode('This is the title');
$text = $title->appendChild($text);

$doc->save("test.xml");
echo "<br>end";
?>

RESULT

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

Thank you!

Tiago Martins Peres
  • 14,289
  • 18
  • 86
  • 145
Andrea php
  • 393
  • 4
  • 21

1 Answers1

0

I have solve the problem with change the permissions from 755 to 777

Andrea php
  • 393
  • 4
  • 21