fwrite()書かれているものはありません、空白のエントリ
質問
$is_file_1
と $is_file_2
どちらも偽ですが、何も挿入されていません 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();
解決
あなたは使用しています ==
代わりに =
の:
$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";
その結果、4つの変数は未定義のままです。そして、新しいラインで追加されたファイルにそれらを書き込もうとするとき、あなたが見るのは新しいラインだけです。これはあなたを仮定しています fopen
成功します。
君 しなければならない 常にの返品値を確認してください fopen
先に進んで、file-ioを行う前に。
他のヒント
間違った演算子の使用に加えて、あなたも使用することができます error_log
独自のエラーログ関数の代わりに:
$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");
}
所属していません StackOverflow