If I try to import a csv file, all the empty rows also get imported.
I have a form which takes a csv file
Following is the form action code
$file = $_FILES['file']['tmp_name'];
$allowedExts = array("csv");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if (!in_array($extension, $allowedExts)) {
$this->session->set_flashdata('msg', 'Please upload a csv file format.');
}
else {
$handle = fopen($file, "r");
$c = 0;
$flag = true;
while(($filesop = fgetcsv($handle, 0, ",")) !== false)
{
if($flag) { $flag = false; continue; } //to skip the title row
if($filesop != NULL ) { //CONDITION TO CHECK EMPTY ROWS (DOES not work..)
$data[] = array(
'id'=>0, //uploader user id
'field1' => (isset($filesop[14]) ? $filesop[14] : "" ),
'field2' => (isset($filesop[15]) ? $filesop[15] : "" ),
'field3' => (isset($filesop[1]) ? $filesop[1] : "" ),
'field4' => (isset($filesop[13]) ? $filesop[13] : "" ),
'field5' => (isset($filesop[6]) ? $filesop[6] : "" ),
'field6' => (isset($filesop[2]) ? $filesop[2] : "" ),
'field7' => (isset($filesop[5]) ? $filesop[5] : "" ),
'field8' => (isset($filesop[3]) ? $filesop[3] : "" ),
'field9' => (isset($filesop[4]) ? $filesop[4] : "" ),
);
}
}
echo "<pre>";
print_r($data);
exit;
Please help me fix , what can I do so that the empty rows do not get imported