php - Errno=9 php 中的错误文件描述符
问题描述
我正在尝试使用以下代码在 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(): write of 66 bytes failed with errno=9 Bad file descriptor in E:\xampp\htdocs\host\host\storyedit.php 第 20 行
警告:fread():第 22 行 E:\xampp\htdocs\host\host\storyedit.php 中的长度参数必须大于 0
注意:未定义的偏移量:第 27 行 E:\xampp\htdocs\host\host\storyedit.php 中的 1
但是代码中没有错误(我认为)。有人可以帮助我吗?
我试过了:
- 删除 php.ini 中的 opcache.enable_cli=1
- 删除缓存
没有工作。
解决方案
您以读取权限打开,然后发出写入命令>您需要以读/写权限打开
$handle = fopen($filename, "r+");
关于 fread 中的错误,请尝试
if (filesize($filename) > 0) {
$content = fread($handle, filesize($filename));
}
推荐阅读
- python - 此代码应反转列表,但仅交换第一个和最后一个元素
- amazon-web-services - 位于运行脚本的 EC2 实例上的 S3 中的 EMR 日志在哪里?
- c++ - 在 CppUnit 中测试中止断言失败
- vba - VBA/规则更改传入电子邮件的主题行然后移动到文件夹
- angular - Angular DataTable(grid) 未与给定的 Json 数据绑定
- python - PANDAS 用逗号分隔符拆分列,列拆分数未知
- c# - 使用 post 调用 Web 服务器得到内部服务器错误
- ios - 致命异常:NSInternalInconsistencyException 如何找到违规代码?
- javascript - 如何正确地将 C# 对象列表解析为 Javascript。仅显示“System.Collections.Generic.List`1”之类的类型
- xml - 使用 XSD 确保 XML 验证中的字符串不为空