Pregunta

$is_file_1 y $is_file_2 son falsas sin embargo, nada se inserta en el archivo errlog-Batch.txt que puse. No estoy seguro de lo que estoy haciendo mal ya que ningún error de script se emite

$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();
¿Fue útil?

Solución

Está utilizando == en lugar de = en:

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

Como resultado permanecen indefinidos las cuatro variables. Y cuando intenta escribirlos en el archivo adjunto con una nueva línea, todo lo que ves es una nueva línea. Esto es suponiendo que su fopen tiene éxito.

debe compruebe siempre el valor de retorno de fopen antes de seguir adelante y hacer archivo-io.

Otros consejos

Además de la utilización del operador mal, podría también utilizar error_log en lugar de su propia función de registro de errores:

$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");
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top