Search code examples
phpcssformsdomdocument

Pushing user button to generate a file does not work


Below code should generate a file.

Question: Why is'nt the file being created?

index2.php

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>

</html>

<form method="post" action="run.php">
        <input
          id="button_1"
          type="submit"
          name="button_1"
          value="Send"
        >
</form>

</body>
</html>

run.php

# -----------------------
# Button event listeners.
# -----------------------

if (isset($_POST["button_1"])) {
  ConstructDocument();
}

// DOMDocument

function ConstructDocument()
{

// Root
$xml = new DomDocument('1.0', 'UTF-8');
$xml->formatOutput = true;

// Elememet
$xbrli = $xml->createElement('xbrli:xbrl');
$xml->appendChild($xbrli);

// Print & Save.
echo $xml->saveXML();
$xml->save("auto_produced_xbrl.xhtml");

}

Solution

  • You need to set the folder you are writing in, to user www-data:www-data. To isolate the given permission, it is recommened that you create a separate folder and provide permission only on that folder. The above mentioned user/group represents any user that access the webserver through a browser.