首页 > 解决方案 > 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)计算机上托管这个脚本

标签: phphtmlapachepermissionschmod

解决方案


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


推荐阅读