1

$is_file_1とはどちらも falseですが、設定したファイル$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();
4

2 に答える 2

3

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

その結果、4 つの変数は未定義のままになります。そして、改行が追加されたファイルにそれらを書き込もうとすると、改行だけが表示されます。fopenこれはあなたが成功したと仮定しています。

file-io を実行する前に、常に の戻り値を確認する必要があります。fopen

于 2010-12-12T16:39:05.403 に答える
1

間違った演算子の使用に加えて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");
}
于 2010-12-12T16:48:37.257 に答える