PHP 5.3 fwrite()期望参数1为资源错误 [英] php 5.3 fwrite() expects parameter 1 to be resource error
本文介绍了PHP 5.3 fwrite()期望参数1为资源错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用wamp服务器.我尝试写入文件,但出现这样的错误:警告:fwrite()期望参数1为资源,给定布尔值".我该怎么解决?
I am using wamp server. I try to write into the file but it is giving such error: "Warning: fwrite() expects parameter 1 to be resource, boolean given ". How can I solve it?
$file = 'file.txt';
if (($fd = fopen($file, "a") !== false)) {
fwrite($fd, 'message to be written' . "\n");
fclose($fd);
}
推荐答案
移动括号:
if (($fd = fopen($file, "a")) !== false) {
fwrite($fd, 'message to be written' . "\n");
fclose($fd);
}
您的代码将(fopen($file, "a") !== false)
(即布尔值)的结果分配给$fd
.
Your code assigned the result of (fopen($file, "a") !== false)
(i.e. a boolean value) to $fd
.
这篇关于PHP 5.3 fwrite()期望参数1为资源错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文