我试图用以下代码在 php 中编写一个文件
    $filename = "uploads/stories/".$row['s_source'];
    $handle = fopen($filename, "r");
    if (filesize($filename) == 0) {
      $txt = "{====views====}{====likes====}{====chapters====}{====comments====}";
      fwrite($handle, $txt);
    }
    $content = fread($handle, filesize($filename));
    fclose($handle);
我得到:
注意:fwrite(): 66 字节写入失败,errno=9 第 20 行 E:\xampp\htdocs\host\host\storyedit.php 中的错误文件描述符
警告:fread():第 22 行 E:\xampp\htdocs\host\host\storyedit.php 中的长度参数必须大于 0
注意:第 27 行 E:\xampp\htdocs\host\host\storyedit.php 中未定义偏移量:1
但代码中没有错误(我认为)。有人可以帮助我吗?
我试过了:
没有一个起作用。
小智 8
您以读访问权限打开r,然后发出写命令>。您需要以读/写访问权限打开:
$handle = fopen($filename, "r+");
关于 中的错误fread,请尝试:
if (filesize($filename) > 0) {
    $content = fread($handle, filesize($filename));
}