Here's a script that seems a little hairy but does a good job of finding the delimiter, line breakes. It also figures out if the fields are enclosed in quotes or not.
// COUNTING THE QUOTES
$fp = fopen ($file,"r");
$line = fgets($fp, 1000);
$quote_array = explode("\"", $line);
// COUNTING THE TABS
$fp = fopen ($file,"r");
$line = fgets($fp, 1000);
$tab_array = explode("\t", $line);
fclose ($fp);
// COUNTING THE COMMAS
$fp = fopen ($file,"r");
$line = fgets($fp, 1000);
$comma_array = explode(",", $line);
fclose ($fp);
// COUNTING THE \Ns
$fp = fopen ($file,"r");
$line = fread($fp, 10000);
$n_array = explode("\n", $line);
fclose ($fp);
// COUNTING THE \Rs
$fp = fopen ($file,"r");
$line = fread($fp, 10000);
$r_array = explode("\r", $line);
fclose ($fp);
// COUNTING THE \R\Ns
$fp = fopen ($file,"r");
$line = fread($fp, 10000);
$rn_array = explode("\r\n", $line);
fclose ($fp);
$tabcount = count($tab_array);
$commacount = count($comma_array);
$rcount = count($r_array);
$ncount = count($n_array);
$rncount = count($rn_array);
$quotecount = count($quote_array);
$halfquote = (($quotecount)/2);
$maxcommatab = max($commacount, $tabcount);
$maxterm = max($rcount, $ncount, $rncount);
if ($maxterm==$rcount) {
$term="\r";
}
if ($maxterm==$ncount) {
$term="\n\";
}
if ($maxterm==$rncount) {
$term="\r\n";
}
//echo "the term is $term<br>";
if ($commacount < $tabcount) {
$delimit="\t";
} else {
$delimit=",";
}
$quotediff = ($maxcommatab-$halfquote-$blankcount);
if ($quotediff < 0) {
$quotediff = ($quotediff*(-1));
}
if ($quotediff < 5) {
echo "the fields are enclosed in quotes<br>";
$enclosed = " enclosed by '\"'";
echo "$enclosed<br>";
}
$query="load data infile \"/path/to/$import_file\" into table $temp_table fields terminated by '$delimit'$enclosed lines terminated by '$term'";