fwrite() 没有写入任何内容,空白条目
$is_file_1
和 $is_file_2
都是 false,但没有任何内容插入到我设置的 errlog-Batch.txt
文件中。我不确定我做错了什么,因为没有输出脚本错误
$dirchk1 = "/temp/files/" . $ch_id . "/" . $data[0];
$dirchk2 = "/temp/files/" . $ch_id . "/" . $data[1];
$is_file_1 = is_file($dirchk1);
$is_file_2 = is_file($dirchk2);
$missing_n == 'file does not exist : ' . '".$data[0]."' . "\r";
$missing_s == 'file does not exist : ' . '".$data[1]."' . "\r";
$renfile_n == 'file can not be move file : ' . '".$data[0]."' . "\r";
$renfile_s == 'file can not be move file : ' . '".$data[1]."' . "\r";
$handle = @fopen("/rec/" . "errlog-" . $batchid . ".txt", "a");
if($is_file_1 == FALSE) {
fwrite($handle, $missing_n . "\n");
} elseif ($is_file_2 == FALSE) {
fwrite($handle, $missing_s . "\n");
}
@fclose($handle);
//exit();
$is_file_1
and $is_file_2
are both false yet nothing is inserted into the errlog-Batch.txt
file that I set. I'm not sure what i'm doing wrong since no script error is outputted
$dirchk1 = "/temp/files/" . $ch_id . "/" . $data[0];
$dirchk2 = "/temp/files/" . $ch_id . "/" . $data[1];
$is_file_1 = is_file($dirchk1);
$is_file_2 = is_file($dirchk2);
$missing_n == 'file does not exist : ' . '".$data[0]."' . "\r";
$missing_s == 'file does not exist : ' . '".$data[1]."' . "\r";
$renfile_n == 'file can not be move file : ' . '".$data[0]."' . "\r";
$renfile_s == 'file can not be move file : ' . '".$data[1]."' . "\r";
$handle = @fopen("/rec/" . "errlog-" . $batchid . ".txt", "a");
if($is_file_1 == FALSE) {
fwrite($handle, $missing_n . "\n");
} elseif ($is_file_2 == FALSE) {
fwrite($handle, $missing_s . "\n");
}
@fclose($handle);
//exit();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在以下位置使用
==
代替=
:因此,四个变量仍然未定义。当您尝试将它们写入附加换行符的文件时,您看到的只是换行符。这是假设您的
fopen
成功。在继续执行 file-io 之前,必须始终检查
fopen
的返回值。You are using
==
in place of=
in:As a result the four variables remain undefined. And when you try to write them to the file appended with a newline, all you see is a newline. This is assuming your
fopen
succeeds.You must always check the return value of
fopen
before you go ahead and do file-io.除了使用错误的运算符之外,您还可以使用
error_log
代替您自己的错误日志功能:Besides the usage of the wrong operator, you could also use
error_log
instead of your own error log function: