Hi traq.
Sorry for the long response time. I did manage to fix this issue the way you described above. here is the code is used:
Code:
if($continue == 2)
{
$seperators = $_POST['field_separate_char'];
$our_name = $tempdir.'/'.basename($_POST['fnames']);
$new_file = $tempdir.'/'.basename($User->id.'.csv');
if(file_exists($new_file)){
unlink($new_file);
}
if(!file_exists($our_name)){
echo 'The file did not upload. Please try the process again.';
exit;
} else {
if($seperators == ''){
$separat = CSV::try_separators( CSV::get_line($our_name) );
if( empty($separat ) ) {
exit( 'Cannot autodetect the separator' );
}
$seperators = $separat;
}
$nlines = explode("\r\n",file_get_contents($our_name));
$arr_head = CSV::get_header_fields( $db, $our_name, 'utf8', $seperators, '"', '\\' );;
$num = count($arr_head);
$nwFile = fopen($new_file, 'w');
$newarray ='';
foreach (array_values($nlines) as $value){
if($value != '') {
$nnmu = explode($seperators, $value);
$totnum = count($nnmu);
if($totnum == $num){
$newarray .= $value.','.$User->id."\n";
}
}
}
fwrite($nwFile,$newarray);
fclose($nwFile);
unlink($our_name);
$_SESSION['csvdata']['file_name'] = $new_file;
$_SESSION['csvdata']['use_csv_header'] = $_POST['use_csv_header'];
$_SESSION['csvdata']['field_separate_char'] = $seperators;
$_SESSION['csvdata']['field_enclose_char'] = '"';
$_SESSION['csvdata']['field_escape_char'] = '\\';
$_SESSION['csvdata']['encoding'] = 'utf8';
$_SESSION['csvdata']['table'] = 'jos_mycont';
$_SESSION['csvdata']['thisuid'] = $thisJRUser->id;
echo '1';
exit;
}
}
Bookmarks