我正在尝试使用以下代码在 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);
然后我得到:
Notice: fwrite(): write of 66 bytes failed with errno=9 Bad file descriptor in E:\xampp\htdocs\host\host\storyedit.php on line 20
Warning: fread(): Length parameter must be greater than 0 in E:\xampp\htdocs\host\host\storyedit.php on line 22
Notice: Undefined offset: 1 in E:\xampp\htdocs\host\host\storyedit.php on line 27
但是代码中没有错误(我认为)。有人可以帮助我吗?
我试过:
- 删除 php.ini 中的 opcache.enable_cli=1
- 删除缓存
没有效果。
最佳答案
您以读权限打开,然后给出写命令>您需要以读/写权限打开
$handle = fopen($filename, "r+");
关于fread中的error,try
if (filesize($filename) > 0) {
$content = fread($handle, filesize($filename));
}
关于php - Errno=9 错误的文件描述符在 php 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61568204/