开发者

While statement with file_exists / is_file doesn't process completely

开发者 https://www.devze.com 2023-01-29 22:30 出处:网络
Strange issue i\'m having. when I perform a file check with File_exist or is_file it only checks half the files... what my script does is processes a csv file and inserts the data into the table only

Strange issue i'm having. when I perform a file check with File_exist or is_file it only checks half the files... what my script does is processes a csv file and inserts the data into the table only if the file exist on the server. if I remove the file check everything processes fine. I've double check to make sure all files exist on the server it just stop half way through for some reason.

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


Try it using "-e" test condition. For eg ::

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

Also make sure if your variable $dirchk1 etc are getting correctly populated or not. Please check if it works or not.


the script processed correctly, human error whey verifying on my part.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号