Ext JS ve PHP Dosya yükleme ve ayrıştırma hatası

0 Cevap php

I am trying to upload a text file with more than one record but I keep getting a syntax() error. only one record in the file varsa uygulanan mantık çalışıyor. Could the problem be that I am echoing multiple records in my foreach loop?

Description:

Ext JS interface where the user browses for a file. Once file is selected it is then uploaded to the server and parsed in PHP. The parsed process is called processFile which is called by the js file.

What I have noticed

  1. only one record in the file varsa uygulanan mantık çalışıyor.
  2. Json biçimi doğrudur.
  3. Dosya varsa, 3 dördüncü BOŞ rekor hala okunur kaydeder.

Herewith the PHP code:

<?php

$action = $_REQUEST['action'];
if ($action == 'uploadFile') {
  $fileName = $_FILES['file']['tmp_name'];
  $fileContent = file_get_contents($fileName);
  $fileInfo = parseFile($fileContent); //custom formatting 
    echo wrap_answer(array(
    'originalFile' => $fileContent,    
    'fileInfo' => $fileInfo,
    'success' => true
    ));  
}

if ($action == 'processFile') {
  $fileContent = $_REQUEST['file'];
  $fileInfo = parseFile($fileContent);  

  foreach($fileInfo['lines'] as $line) {        
    $input = array(
            'id' => $line['id'],
            'name' => $line['name']);              
    //custom function to insert records from file into clients table
    //function returns the inserted records ID  
    $insert_id = handler_Insert('clients',$input);    

    $success = ($insert_id == null || $insert_id == 0)?false:true;
    echo json_encode(array(
    'success' => $success)
    );    
    //NOTE:Processing records 1 by 1 and echoing the result
    //     Could this be the error? Any suggestions to better
    //     handle this process?
  }
}

Any help,suggesstions etc much appreciated! Thanks

0 Cevap