file.csv structure:
Before uploading to folder upload, I want to check the column.
The algorithm is like:
if ((column 1 = 'no') && (column 2 = 'product_name') && (column 3 = 'product_price') && (column 4 = 'qty'))
{
upload();
}
else
{
die;
}
Is there any coding for this case using php coding or sql to validate?
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