I'm working on a project for a fairly computer-illiterate client of mine. This portion of it will accept client contacts from another company listed in .csv format and add them to an sql database which feeds a large digital rolodex.
Let me start by saying that I am a designer, not a programer, so if this is really easy or stupid sounding, please bear-with.
I have a script now that allows you to select a .csv file from your local machine and upload it to a server, then parse the .csv file to a set of arrays. Here is the source code:
<body>
<?
if(isset($_POST['upload']))
{
$filename = ($_FILES['userfile']['tmp_name']);
$handle = fopen($filename, 'r');
$row = 1;
while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {
$num = count($data);
echo "<br />";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br />\n";
}
}
fclose($handle);
}
?>
<form action="" method="post" enctype="multipart/form-data" name="uploadform">
<table width="350" border="0" cellpadding="1" cellspacing="1">
<tr>
<td width="246"><input name="userfile" type="file" id="userfile">
</td>
<td width="80"><input name="upload" type="submit" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
</body>
I need this same file to then take these arrays and insert them into a pre-existing sql database.
One more catch, the first row of each file, and therefor the first array, identifies the column. I don't beleive the order or number of these will ever change, so I may need to eliminate the first row of the file when parsing.
Like I said, this client is not very good with computers, so this needs to be a "select the file and click go" process so as not to confuse him.
Thank you for your help.