Try chown -R www-data:www-data /path-to-root-directory
Solution 1 :
Problem :
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
Comments
Comment posted by RiggsFolly
but it gives an error
Comment posted by Bluppie05
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
Comment posted by Bluppie05
Now it is just not working, It isn’t spitting out any error
Comment posted by error reporting
Add
Comment posted by Alexandro Setiawan
yeah sorry. edited
Comment posted by Bluppie05
Do I need to run this command in my linux terminal or do I need to paste this in my script?
Comment posted by Bluppie05
and do you mean by root directory /var/www/html or /var/www or something else?
Comment posted by Alexandro Setiawan
run in your linux terminal
Comment posted by Alexandro Setiawan
yes /var/www/html (if default)