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
- only one record in the file varsa uygulanan mantık çalışıyor.
- Json biçimi doğrudur.
- 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