0

I am trying to make a notepad application which saves files if you press save, but it gives an error. I think the script(or apache) doesn't have the permissions to write to the disk but I might be wrong.

Does anyone know what to change about my code or how to set the permissions? It would be heavily gracious and appreciated if someone could fix this problem for me.

Code(Yes I know this is spaghetti-code but this is how I learned html and php):

<html>
<style>
button {
    display: inline-block;
    background-color: #4CAF50;
    padding: 15px 32px;
    font-size: 16px;
    font-size: 16px;
    color: white;
    text-align: center;
    border: none;

}
</style>
<style>
    input {
    display: inline-block;
    background-color: #4CAF50;
    padding: 15px 32px;
    font-size: 16px;
    font-size: 16px;
    color: white;
    text-align: center;
    border: none;

}
</style>
<center><b><font size="7">Notepad</font></b></center>
<br>
<center><form>
        <textarea rows="1" cols="50" name="filename">filename</textarea>
        <br>
        <textarea rows="1" cols="50" name="text">Lorem ipsum</textarea>
        <input type="submit" name="submit" value="save">
    </form></center>
<br>
</html>
<?php

if(isset($_GET['text'])) {
    $text = $_GET['text'];
    $filename = $_GET['filename'];

    $myfile = fopen("$filename", "w") or die("Unable to open file!");
    $txt = $text;
    fwrite($myfile, $txt);
    fclose($myfile);

    echo("<center>Your file is saved as $filename</center>");
}

?>

BTW: I am hosting this script on my LinuxMint(Ubuntu linux) computer using Apache2 and PHP

Bluppie05
  • 113
  • 8
  • 4
    **but it gives an error** So would you tell us the error (ALL OF IT) just in case it might be relevant – RiggsFolly Feb 17 '20 at 15:59
  • Thanks for commenting, it is giving the error: Unable to open file, wait I will remove the or die part so I can see the exact error – Bluppie05 Feb 17 '20 at 16:00
  • Now it is just not working, It isn't spitting out any error – Bluppie05 Feb 17 '20 at 16:03
  • Add [error reporting](http://stackoverflow.com/questions/845021/) to the top of your file(s) _while testing_ right after your opening PHP tag for example ` – RiggsFolly Feb 17 '20 at 16:05

1 Answers1

1

Try chown -R www-data:www-data /path-to-root-directory