PHP:写入磁盘权限



我正在尝试制作一个记事本应用程序,如果按save键,它会保存文件,但会出错。我认为脚本(或apache(没有写入磁盘的权限,但我可能错了。

有人知道要更改我的代码或如何设置权限吗?如果有人能帮我解决这个问题,我将不胜感激。

代码(是的,我知道这是意大利面条代码,但这就是我学习html和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:我正在我的linux Mint(Ubuntu linux(计算机上使用Apache2和PHP 托管这个脚本

尝试chown -R www-data:www-data /path-to-root-directory

最新更新