PHP写入文件而不写入文件

时间:2012-06-03 19:47:28

标签: php

我希望我的php文件将一些文本写入我创建的文本文件中,但没有任何内容写入它。

以下是代码:

<?php
    error_reporting(E_ALL);
    ini_set('display_errors', '1');

    if (isset($_POST['comment']))
    {
        $comment = $_POST['comment'];

        $myFile = "testFile.txt";
        $fh = fopen($myFile, 'w') or die("can't open file");
        $stringData = $comment;
        fwrite($fh, $stringData);
        fclose($fh);
    }
    else
    {
        $comment = 'no comment';

        $myFile = "testFile.txt";
        $fh = fopen($myFile, 'w') or die("can't open file");
        $stringData = $comment;
        fwrite($fh, $stringData);
        fclose($fh);
    }
?>

1 个答案:

答案 0 :(得分:2)

检查文件权限。

如果出现问题,请尝试更改权限:

chmod("testFile.txt", 0644);
相关问题