1

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

结果,四个变量仍未定义。当您尝试将它们写入附加换行符的文件时,您看到的只是换行符。这是假设你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 回答