I have a code which should save content from a text area as a text file using PHP, File is getting created if I click the button, but no data is written inside that.
Code:
<form method="POST" action="">
<div data-label="Index.php" class="demo-code-preview" contentEditable="true">
<pre><code class="language-html">
<textarea name="content">
<?php
$file = "index.php";
echo(htmlspecialchars(file_get_contents($file)));
?>
</textarea>
</code></pre>
</div>
</a>
<a href="?SubmitFile=true" class="bar-anchor" name="SaveFile">
<span>Save</span>
<div class="transition-bar"></div>
</a>
</form>
<?php
if (isset($_GET['SubmitFile'])){
$content = $_POST['content'];
echo "<script>console.log('" . $content . "' );</script>";
$file = "myfile.txt"; // cannot be an online resource
$Saved_File = fopen($file, 'a+');
fwrite($Saved_File, $content);
fclose($Saved_File);
}
?>