Upload Multiple Files in one form

Ask a Question related to Macromedia ColdFusion, Design and Development.

  1. #1

    Default Upload Multiple Files in one form

    I am trying to upload the track information for cd's, and also upload the audio
    sample files at the same time. The samples are real media at this point (not my
    choice) but...anyways...

    I have a page that asks how many tracks? then the next page takes that and
    creates the input box's for track numbers track names and file input fields. I
    am attaching the code I have so far, that I cannot get to work. I am not sure
    where to go from here. I am not able to able to get the right name of the
    sample to the database or get the file to upload to the directory.

    <cfloop from="1" to="#form.numba#" index="idx">
    <cfset gettrack_number = evaluate("form.track_number" & idx)>
    <cfset gettrack_name = evaluate("form.track_name" & idx)>
    <cfset getsample_file = evaluate("file.ServerFileName" & idx)>
    <cfquery name="data" datasource="klaritymusic">
    insert into tracks (album_id,track_number,track_name,sample)
    values
    (#form.album_id#,#gettrack_number#,'#gettrack_name #','#getsample_file#')
    </cfquery>
    </cfloop>

    <cfloop from="1" to="#form.numba#" index="idx">
    <cfset GetSample = evaluate("file" & idx)>
    <CFFILE ACTION="upload"
    FILEFIELD="#GetSample#"
    DESTINATION="D:\Sites\ecsmaine.com\wwwroot\klarity music\samples"
    NAMECONFLICT="MAKEUNIQUE">

    </cfloop>

    StylusDesigns Guest

  2. Similar Questions and Discussions

    1. Multiple Image Upload Form w. Flash
      I need to build a form to allow users to upload many image files all from the same page. Can Flash be used to do this? If so, please tell me what...
    2. upload multiple files
      Hi, I have the form where user can upload max to three files at the same time. Also the file is need to be overrtie if user try to post the same...
    3. upload multiple files is this possible?
      Hi guys! is this possible to upload a whole directory or at least all files in a directory at once ? I know how to do it with 10 files then you...
    4. Multiple upload files with php
      Hi, I need to upload multiples files using php, but with the same "<input>" tag, somebody can help my, is this feature supported by php?. Anyboy...
    5. multiple files upload
      Hi Group, In my program, the user has to be able to add one or more documents (as files) for one product from the database. The number of files...
  3. #2

    Default Upload Multiple Files in one form

    I am trying to upload the track information for cd's, and also upload the audio
    sample files at the same time. The samples are real media at this point (not my
    choice) but...anyways...

    I have a page that asks how many tracks? then the next page takes that and
    creates the input box's for track numbers track names and file input fields. I
    am attaching the code I have so far, that I cannot get to work. I am not sure
    where to go from here. I am not able to able to get the right name of the
    sample to the database or get the file to upload to the directory.

    <cfloop from="1" to="#form.numba#" index="idx">
    <cfset gettrack_number = evaluate("form.track_number" & idx)>
    <cfset gettrack_name = evaluate("form.track_name" & idx)>
    <cfset getsample_file = evaluate("file.ServerFileName" & idx)>
    <cfquery name="data" datasource="klaritymusic">
    insert into tracks (album_id,track_number,track_name,sample)
    values
    (#form.album_id#,#gettrack_number#,'#gettrack_name #','#getsample_file#')
    </cfquery>
    </cfloop>

    <cfloop from="1" to="#form.numba#" index="idx">
    <cfset GetSample = evaluate("file" & idx)>
    <CFFILE ACTION="upload"
    FILEFIELD="#GetSample#"
    DESTINATION="D:\Sites\ecsmaine.com\wwwroot\klarity music\samples"
    NAMECONFLICT="MAKEUNIQUE">

    </cfloop>

    forumnotifier Guest

  4. #3

    Default Re: Upload Multiple Files in one form

    I made some headway, but I still cannot get the correct data into the database,
    but I can get the songs to upload.

    here is the code:

    --------------------------------------------------------------------------------
    -------------------------------------------------------------------------
    <cfloop from="1" to="#form.numba#" index="idx">
    <cfset gettrack_number = evaluate("form.track_number" & idx)>
    <cfset gettrack_name = evaluate("form.track_name" & idx)>
    <cfset sample = evaluate('form.sample' & idx)>
    <cfquery name="data" datasource="klaritymusic">
    insert into tracks (album_id,track_number,track_name,sample)
    values (#form.album_id#,#gettrack_number#,'#gettrack_name #','#sample#')
    </cfquery>
    </cfloop>

    <cfset sample = 'sample'>
    <cfloop from="1" to="#form.numba#" index="idx">
    <cfif (IsDefined("FORM.sample#idx#")) AND (#Evaluate("FORM.sample#idx#")# neq
    "")>
    <cffile
    action="upload"
    filefield="sample#idx#"
    DESTINATION="D:\Sites\ecsmaine.com\wwwroot\klarity music\samples"
    NAMECONFLICT="MAKEUNIQUE">

    </cfif>
    </cfloop>

    --------------------------------------------------------------------------------
    --------------------------------------------------------------------

    In the database the sample is listed as "sample

    D:\CFusionMX\runtime\servers\default\SERVER-INF\temp\wwwroot-tmp\neotmp45401.tmp
    " instead of the file name.

    Please Help.

    StylusDesigns Guest

  5. #4

    Default Re: Upload Multiple Files in one form

    I have attached some quick code I put together (untested)
    But basically you need to process each file form field (file upload) seperately

    See attached code

    Ken

    <!--- The form page --->
    <form action="action_page.cfm" method="post" enctype="multipart/form-data"
    name="form1" id="form1">
    <!--- Need to know how may form fields to process, also need to pass this onto
    the action page --->
    <input type="hidden" name="form.numba"
    value="<cfoutput>#form.numba#</cfoutput>">
    <cfloop from="1" to="#form.numba#" index="idx">
    <input type="text" name="track_name#idx#">
    <input type="file" name="track#idx#">
    </cfloop>
    <input type="submit" name="submit" value="Upload">
    </form>

    <!--- The action page --->
    <cfloop from="1" to="#form.numba#" index="idx">
    <!--- process each file upload seperately --->
    <!--- upload the file(s) --->
    <CFFILE ACTION="upload"
    FILEFIELD="#form['track' & idx]#"
    DESTINATION="D:\Sites\ecsmaine.com\wwwroot\klarity music\samples"
    NAMECONFLICT="MAKEUNIQUE">
    <!--- insert the record into data base --->
    <cfquery name="data" datasource="klaritymusic">
    insert into tracks (album_id,track_number,track_name,sample)
    values (#form.album_id#,#gettrack_number#,'#form["track_name" &
    idx]#','#ServerFileName#')
    </cfquery>
    </cfloop>

    The ScareCrow Guest

  6. #5

    Default Re: Upload Multiple Files in one form

    I could not get the code to work that was recommended,

    here is what I have now

    <cfloop from="1" to="#form.numba#" index="idx">
    <cfif (IsDefined("FORM.sample#idx#")) AND (#Evaluate("FORM.sample#idx#")# neq
    "")>
    <cffile action="upload" filefield="sample#idx#"
    DESTINATION="D:\Sites\ecsmaine.com\wwwroot\klarity music\samples"
    NAMECONFLICT="MAKEUNIQUE">
    </cfif>

    <cfset gettrack_number = evaluate("form.track_number" &
    idx)>
    <cfset gettrack_name = evaluate("form.track_name" & idx)>
    <cfset getsample_name = '#cffile.ServerFileName#'>
    <cfquery name="data" datasource="klaritymusic">
    insert into tracks (album_id,track_number,track_name,sample)
    values
    (#form.album_id#,#gettrack_number#,'#gettrack_name #','#getsample_name#')
    </cfquery>
    </cfloop>

    I am stuck on the cffile.serverfilename cannot get it to return a value. The
    error message I get is "Element SERVERFILENAME is undefined in CFFILE. "

    Thanks

    StylusDesigns Guest

  7. #6

    Default Re: Upload Multiple Files in one form

    The attached code is a working example.

    While it did not insert a record into a table, it does output the sql
    statement, which is correct if the other (column) values are supplied.

    All you need to do is copy the 3 pages and save them and run. Once you
    understand what the code is doing, then change it to meet your needs

    Ken

    PAGE ONE
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>Untitled</title>
    </head>

    <body>
    <form action="page2.cfm" method="post" name="form1" id="form1">
    <p>Please select how many files to upload</p>
    <p>
    <select name="numba">
    <cfloop from="1" to="10" index="idx">
    <cfoutput>
    <option value="#idx#">#idx#</option>
    </cfoutput>
    </cfloop>
    </select>
    </p>
    <input type="submit" name="submit" value="Submit">
    </form>


    </body>
    </html>


    PAGE TWO
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>Untitled</title>
    </head>

    <body>
    <form action="page3.cfm" method="post" enctype="multipart/form-data"
    name="form2" id="form2">
    <!--- Need to know how may form fields to process, also need to pass this onto
    the action page --->
    <input type="hidden" name="numba" value="<cfoutput>#form.numba#</cfoutput>">
    <cfoutput>
    <cfloop from="1" to="#form.numba#" index="idx">
    <input type="text" name="track_name#idx#"> <input type="file"
    name="track#idx#"><br>
    </cfloop>
    </cfoutput>
    <input type="submit" name="submit" value="Upload">
    </form>

    </form>


    </body>
    </html>

    PAGE THREE
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>Untitled</title>
    </head>

    <body>
    <!--- The action page --->
    <cfloop from="1" to="#form.numba#" index="idx">
    <!--- process each file upload seperately --->
    <!--- upload the file(s) --->
    <cfset field = "track#idx#">
    <cffile action="UPLOAD" filefield="#field#"
    destination="D:\Sites\ecsmaine.com\wwwroot\klarity music\samples" result=""
    nameconflict="MAKEUNIQUE">
    <!--- insert the record into data base --->
    <!--- <cfquery name="data" datasource="klaritymusic"> --->
    <cfoutput>
    insert into tracks (album_id,track_number,track_name,sample)
    values (form.album_id,gettrack_number,'#form["track_name" &
    idx]#','#cffile.serverFile#')
    </cfoutput>
    <!--- </cfquery> --->
    </cfloop>



    </body>
    </html>

    The ScareCrow Guest

  8. #7

    Default Re: Upload Multiple Files in one form

    Thank you very much for the code & help. I did get it to work, I used your
    code, I taylored it a little bit to fit, then realized my errors which I don't
    think I mentioned to you that only some of the tracks get a sample file, not
    all. So when it was coming back and saying that it couldn't find the
    cffile.serverfilename thats because I didn't submit a file. I setup a cfif
    cfelse to cover that problem, and it works great now.

    Thanks Again, I attached the final code that made it work.

    <!--- The action page --->
    <cfloop from="1" to="#form.numba#" index="idx">
    <!--- process each file upload seperately --->
    <!--- upload the file(s) --->
    <cfset field = "track#idx#">
    <cfif (IsDefined("#field#")) AND (#Evaluate("#field#")# neq "")>
    <cffile action="UPLOAD" filefield="#field#"
    destination="D:\Sites\ecsmaine.com\wwwroot\klarity music\samples"
    nameconflict="MAKEUNIQUE">
    <!--- insert the record into data base --->
    <cfquery name="data" datasource="klaritymusic">
    <cfoutput>
    insert into tracks (album_id,track_number,track_name,sample)
    values (#form.album_id#,#form["track_number" &
    idx]#,'#form["track_name" & idx]#','#cffile.serverFile#')
    </cfoutput>
    </cfquery>
    <cfelse>
    <cfquery name="data" datasource="klaritymusic">
    <cfoutput>
    insert into tracks (album_id,track_number,track_name)
    values (#form.album_id#,#form["track_number" &
    idx]#,'#form["track_name" & idx]#')
    </cfoutput>
    </cfquery>


    </cfif>
    </cfloop>

    StylusDesigns Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139