Errno=9 php中的错误文件描述符
我试图用php编写一个文件,代码如下Errno=9 php中的错误文件描述符,php,file,Php,File,我试图用php编写一个文件,代码如下 $filename = "uploads/stories/".$row['s_source']; $handle = fopen($filename, "r"); if (filesize($filename) == 0) { $txt = "{====views====}{====likes====}{====chapters====}{====comments====}
$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():在第20行的E:\xampp\htdocs\host\host\storyedit.php中写入66个字节失败,错误号为9
警告:fread():第22行E:\xampp\htdocs\host\host\storyedit.php中的长度参数必须大于0
注意:第27行E:\xampp\htdocs\host\host\storyedit.php中未定义的偏移量:1
但是(我认为)代码中没有错误。有人能帮我吗
我试过:
没有一个有效。您使用读访问权限打开,然后发出写命令>您需要使用读/写访问权限打开
$handle = fopen($filename, "r+");
关于fread中的错误,请尝试
if (filesize($filename) > 0) {
$content = fread($handle, filesize($filename));
}
$filename是否存在且filesize($filename)==0?请注意,即使您以写访问权限打开,如果另一个进程写入该文件,也可能发生此错误。