2010-12-12 41 views
0

奇怪的問題,我有。當我使用File_exist或is_file執行文件檢查時,它只檢查一半的文件...我的腳本執行的操作是處理csv文件,並且只有當文件存在於服務器上時纔會將數據插入到表中。如果我刪除文件檢查一切正常進程。我仔細檢查過,確保所有文件都存在於服務器上,出於某種原因只是中途停止。雖然與file_exists/is_file聲明不完全處理

$column_headers = array(); 
$row_count = 0; 

if (mysql_result(
    mysql_query(
     "SELECT count(*) FROM load_test WHERE batch_id='".$batchid."'" 
    ), 0 
    ) > 0) { 
    die("Error batch already present"); 
} 

while (($data = fgetcsv($handle, 0, ",")) !== FALSE) { 
    if ($row_count==0){ 
    $column_headers = $data; 
    } else { 
    $dirchk1 = "/temp/files/" . $batchid . "/" .$data[0] . ".wav"; 
    $dirchk2 = "/files/" . $batchid . "/" . $data[1] . ".wav"; 

    if (file_exists($dirchk1)) { 

     $importword="INSERT into load_test SET 
      word = '".$data[2]."', 
      batch_id = UCASE('".$batchid."'), 
      accent = '".$data[15]."' 
      "; 

     mysql_query($importword); 
     $word_id = mysql_insert_id(); 
     echo $word_id . "\n"; 
    } 
    } 
    ++$row_count; 
} 
+1

啓用錯誤/警告/通知顯示,看看PHP是否告訴你任何信息。 – Matthew 2010-12-12 08:08:33

+1

你有什麼錯誤嗎?所有文件的權限是否正確(嘗試'file_exists($ file)&& is_readable($ file)')? – prodigitalson 2010-12-12 08:09:35

+1

它停在哪裏?什麼行 – 2010-12-12 08:12:37

回答

0

嘗試使用「-e」測試條件。 對於例如::

 
if(-e $dirchk1){ 
    print "File exists\n"; 
} 

同時確保,如果你的變量$ dirchk1等越來越正確填充與否。 請檢查它是否有效。

+0

解析錯誤:語法錯誤,意外的T_VARIABLE – acctman 2010-12-12 11:34:46

0

腳本處理正確,人爲錯誤乳清檢測我的部分。