开发者

fwrite() nothing being written, blank entries

$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 == FA开发者_C百科LSE) {
    fwrite($handle, $missing_n . "\n");
} elseif ($is_file_2 == FALSE) {
    fwrite($handle, $missing_s . "\n");
}
@fclose($handle);
//exit();


You are using == in place of = in:

$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";

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.


Besides the usage of the wrong operator, you could also use error_log instead of your own error log function:

$dirchk1 = "/temp/files/" . $ch_id . "/" . $data[0];
$dirchk2 = "/temp/files/" . $ch_id . "/" . $data[1];

if (!is_file($dirchk1)) {
    error_log(sprintf('file does not exist: "%s"', $data[0]), 3, "/rec/errlog-$batchid.txt");
}
if (!is_file($dirchk2)) {
    error_log(sprintf('file does not exist: "%s"', $data[1]), 3, "/rec/errlog-$batchid.txt");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜