File import with field maps

I would like to build an import file routine that would allow a user to upload a file, then map fields to rows in the file and then process the upload.  I would like to use this import routine on multiple tables and will be importing large amounts of data.

I am wondering what the best way of doing this would be?   How should this be tackled and if anyone has any sample scripts/tips on this.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

is this a one-time thing?  if so, why aren't you using the import facility within the database software? (assuming you are talking about a database).

Your question is unclear:  when you say "then map fields to rows in the file and then process the upload."  are you talking about fields in a database table?  if so, it seems like you want to map the rows in the file to the cells in a table, not the other way around.  anyway, i'm proceeding on the assumption that you want to upload a text file that has columns delimited by the character found in variable x, and rows delimited by the character found in variable y.  these rows and columns will then be imported into a table.  Also assuming row 1 has the column names.

<cfset x=",">
<cfset y="#chr(13)##chr(10)#">
<cfset yourPath="e:\inetpub\domains\yourdomain\wwwroot\uploaded_files\">
<cfset datasource="yourDSN">

<cffile action="Upload" filefield="ufile" destination="#yourPath#" nameconflict="overwrite">

<cffile action="read" file="#yourpath##file.serverfile#" variable="newfile">

<cfset rowcnt=0>
<cfloop list="#newfile#" index="row" delimiters="#y#">
    <cfset rowcnt=rowcnt+1>
      <cfif rowcnt gt 1>
            <cfquery name="ins" datasource="#datasource#">
                  insert into #form.tablename#
                  <cfset colcnt=0>
                  <Cfloop list="#listfirst(newfile,y)#" index="colname" delimiters="#x#">
                      <cfset colcnt=colcnt+1>
                        <cfif colcnt is not listlen(row)>,</cfif>
                  <cfset colcnt=0>            
                  <Cfloop list="#row#" index="col" delimiters="#x#">
                        <cfset colcnt=colcnt+1>
                        <cfif colcnt is not listlen(row)>,</cfif>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
well, i beleive my solution would work (in a general sense) but if he says otherwise, I suppose he's the one to be testing it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.