【问题标题】:PHP: Write to disk permission [duplicate]PHP:写入磁盘权限[重复]
【发布时间】:2020-06-01 14:30:24
【问题描述】:

我正在尝试制作一个记事本应用程序,如果您按保存,它会保存文件,但它会出错。我认为脚本(或 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)计算机上托管此脚本

【问题讨论】:

  • 但它给​​出了一个错误所以你能告诉我们错误(全部)以防万一它可能是相关的
  • 感谢您的评论,它给出了错误:无法打开文件,等待我将删除 or die 部分,以便我可以看到确切的错误
  • 现在它只是不工作,它没有吐出任何错误
  • error reporting 添加到文件顶部测试时在您打开PHP 标记之后,例如&lt;?php error_reporting(E_ALL); ini_set('display_errors', 1); 以查看它是否产生任何结果。跨度>

标签: php html apache permissions chmod


【解决方案1】:

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

【讨论】:

  • 是的,对不起。已编辑
  • 我需要在我的 linux 终端中运行此命令还是需要将其粘贴到我的脚本中?
  • 你的意思是根目录 /var/www/html 或 /var/www 还是别的什么?
  • 在你的 linux 终端中运行
  • 是 /var/www/html(如果默认)
猜你喜欢
  • 2013-01-02
  • 2010-10-18
  • 1970-01-01
  • 1970-01-01
  • 2011-02-20
  • 2018-09-22
  • 2011-10-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多