We have to load the csv file in location and fetch the csv files content and validate the content.
Here is my example:
$destination=C:\Users\AIT\Desktop\SC MArgins new.csv;
$contents = file ($destination);
for($i=1; $i<sizeof($contents); $i++)
{
$line = trim($contents[$i],'",');
$arr = explode(',',$line);
if($arr[0]=='')
{
$rows.='Item#,';
}
if($arr[1]=='')
{
$rows.='Product Name,';
}
if($arr[2]=='')
{
$rows.='Product Code,';
}
if($arr[3]=='')
{
$rows.='Product Grade,';
}
if($rows!=''){
$row1.='Row '.$i.'-'. $rows.'can not be empty'."<br>";}
$k.=$row1;
}
if($k!='' ){
$common->setMsg($row1, 'box_warning');
return false;
}
This code will help u to get which column is missing. Follow this code and let me know if any issues on processing the csv