Forum Moderators: coopster
I have a two meg delimited ascii file I need to import on a regular basis (26 fields)
Anyone have a nice import routine using fopen they are willing to share before I attempt to hack one out myself? I can't seem to find such an animal out there (though some are close).
Such a shame, from what I have read, load data is much faster...
Thanks for any help!
set_time_limit(5*60);
$filename = "resources.txt";
$delim =",";
$f = fopen ($filename,"r");
while ($data = fgetcsv($f, 2000, $delim)) {
while (list($key,$val) = each($data)){
$data[$key] = addslashes($val);
}
$insert = "INSERT into ".$sql_tbl." VALUES('".implode("','", $data)."')";
$result = mysql_query($insert) or die("error - ".mysql_error());
}
fclose ($f);
The problem is, these folks will be uploading from macs and I don't want them to have extra steps. This datafile will only be growing in size so I don't want to convert in ram or save to disk. Any super-creative ideas anyone?
Getting them to save as a PC file, all Mac programs I have worked with have options for default line endings. Often it says Mac/PC/Unix in the save as.
replacing chars but the file is too big for that.
just thinking out loud, I was looking at different functions like fgets but couldn't find anything I really liked.
Did you get any farther or maybe someone else has some ideas.