php - PHP:写入磁盘权限
问题描述
我正在尝试制作一个记事本应用程序,如果您按保存,它会保存文件,但它会出错。我认为脚本(或 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>");
}
?>
顺便说一句:我使用 Apache2 和 PHP 在我的 LinuxMint(Ubuntu linux)计算机上托管这个脚本
解决方案
尝试chown -R www-data:www-data /path-to-root-directory
推荐阅读
- python - Python Pandas 交换列值
- c++ - 如何读取运行 QProcess 的输出并将特定数据保存到变量?
- docker - 将变量传递给 Dockerfile 并在 Tag 版本中使用它?
- javascript - 从外部文件访问 json 数据
- reactjs - React.js,显示两个彼此相邻的 Svg 图像,中间有空格
- java - 将 MapActivity (FragmentActivity) 添加到 Navigation Drawers (Fragment)
- java - Spring MVC - 逻辑 RestController 和 Service 的分离
- javascript - 关于 Google 语音 API 上的 MicrophoneStram.js 错误
- javascript - 等待不等待前一个代码块被执行
- python - 单击带有 Selenium 和 python 的 CSS 元素