2010-12-12 122 views
1

$is_file_1$is_file_2都是假的,但沒有任何內容插入到我設置的errlog-Batch.txt文件中。我不知道,因爲沒有腳本錯誤輸出fwrite()沒有寫入空白條目

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

如果你刪除了'@單曲? – 2010-12-12 16:38:49

回答

3

你代替=使用==我在做什麼錯:

$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成功。

必須總是檢查返回值fopen然後繼續執行file-io。

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"); 
}