Loading text from an uploaded text file.
Posted: Fri Nov 25, 2011 12:26 pm
Forgive if this has been asked I searched but could not find what i was looking for.
I have a database routine where a user will upload a text file that contains data. Each record of data in the text file ends with <EOR>
Each record can contain a random length of text possibly up to 3000 characters. And can have multiple CR's located in it.
I need to parse out the record up to and including the <EOR>. So once the file is read in up to the end of first <EOR> that string of data would be sent to the parse routines. Then the next record gets read in and so on till the end of the file.
I am using this a to do the routine now but the encountered CR's keep breaking the string to soon and not all of the record is getting read in...
Can someone show me the correct routine I should be using to do this.. This is driving me nuts since I am not that good with PHP yet..
Thanks Rick
I have a database routine where a user will upload a text file that contains data. Each record of data in the text file ends with <EOR>
Each record can contain a random length of text possibly up to 3000 characters. And can have multiple CR's located in it.
I need to parse out the record up to and including the <EOR>. So once the file is read in up to the end of first <EOR> that string of data would be sent to the parse routines. Then the next record gets read in and so on till the end of the file.
I am using this a to do the routine now but the encountered CR's keep breaking the string to soon and not all of the record is getting read in...
Code: Select all
// Read the first line
$string = fgets ($file, 1024);
$string = strtoupper ($string);
if (stristr($string, "<EOR>"))
{
// Process ADIF file
processFile ($file,$count,$duplicate,$Bad,$string,$usertable);
}
else
{
while (($string = fgets ($file,1024)) && !$valid_file)
{
$string = strtoupper ($string);
if (stristr($string, "<EOR>") )
{
$valid_file = 1;
processFile ($file,$count,$duplicate,$Bad,$string,$usertable);
}
}
// No records in file found - exit with an error
if (!$valid_file)
{
echo "<P>Error - Unable to upload file: $browser_name\n";
echo "<P>Invalid file format.\n";
die();
}
}
Thanks Rick