Skip to main content
Known Participant
March 27, 2010
Answered

uploading two files from a form in one go...?

  • March 27, 2010
  • 1 reply
  • 1584 views

Given i have two file input form values on one page, how would i upload them both on the second? This is what i have attempted to do..

FORM ON FIRST PAGE

<form onSubmit="return checkrequired(this)" action="upload2.cfm" method="post" enctype='multipart/form-data'>

Preset Name<br />
<input type=text name="requiredname" ><br>
Genre<br />
<input type=text name="requiredgenre" ><br>
BPM<br />
<input type=text name="requiredbpm" ><br>
Soundslike<br />
<input type=text name="requiredsoundslike" ><br>
Daw required<br />
<input type=text name="requireddaw" ><br>
VSTs required<br />
<input type=text name="requiredvst" ><br>
License<br />
<input type=text name="requiredlicense" ><br>
Instructions<br />
<textarea name="requiredinstructions" cols="20" rows="4" >
</textarea><br>
Preset file:<br/>
<input type='FILE' name='ofname' ><BR>
MP3 preview file:<br/>
<input type='FILE' name='ofname2' ><BR>
<BR>


<input type=submit value="Upload">
</form>

COLDFUSION ON SECOND PAGE


<cfset subdir=#GetCurrentTemplatePath()#>
<cfset subdir='#replace(subdir,'\upload2.cfm','\presets')#'>

<cfset subdir2=#GetCurrentTemplatePath()#>
<cfset subdir2='#replace(subdir2,'\upload2.cfm','\presetsmp3')#'>

<cfif ofname is ''>
<font color="Red" size="3"><b>Choose a file...!</b></font><br><br>
<a href="javascript:history.go(-1)" onMouseOver="self.status=document.referrer;return true"><b>BACK...</b></a>
<cfabort>
</cfif>


<cfset dstfile='#subdir#'>
<CFFILE ACTION="Upload"
    FILEFIELD="ofname"
    DESTINATION="#dstfile#"
    nameconflict="Skip">

<cfset dstfile='#subdir2#'>
<CFFILE ACTION="Upload"
    FILEFIELD="ofname2"
    DESTINATION="#dstfile#"
    nameconflict="Skip">

<cfquery name="newpreset" datasource="062409js06ag">
        insert into presets (artistid, artistname, presetname, presetgenre, bpm, soundslike, daws, vsts, license, pfilename, instructions) values (#findname.ID#, '#findname.uname#', '#requiredname#', '#requiredgenre#', '#requiredbpm#', '#requiredsoundslike#', '#requireddaw#', '#requiredvst#', '#requiredlicense#', '#serverfile#', '#requiredinstructions#')
        </cfquery>  

<CFOUTPUT><B>FILE RECEIVED!<BR></CFOUTPUT>

    This topic has been closed for replies.
    Correct answer Leonard_B

    yooo leonard help me out, the files have to be in different folders, however the names of these files and their extensions i want to keep in the same table... how do i do that???


    iamrobot,

    Have you figured this out, or do you still need some help?

    Leonard B

    1 reply

    Fernis
    Inspiring
    March 27, 2010

    Here's the simple solution:

    Use the result attribute of cffile tag.

    Without the result attribute the serverfile variable etc. go into the CFFILE structure (it is really a good practice to write CFFILE.serverfile instead of just serverfile). When result is defined, for example, result="file1", you'll have result1.serverfile instead of CFFILE.serverfile.

    With CF9 though, you can use <cffile action="uploadall"> , where you'll have an array of results. See CFML 9 pdf reference, page 212.

    --

    - Fernis - fernis.net - ColdFusion Developer For Hire

    ag3900683Author
    Known Participant
    March 27, 2010

    Thanks for your "simple solution".. p.212 of the cfmlref doesn't tell me anything great,and <cffile action="uploadall"> means nothing to me out of context.

    Im trying to upload two files (taken from one form) into separate locations and input both of their names (changed or unchanged) into separate tables in my database. Uploadall definitely doesn't do that.

    Leonard_BCorrect answer
    Inspiring
    April 4, 2010

    yooo leonard help me out, the files have to be in different folders, however the names of these files and their extensions i want to keep in the same table... how do i do that???


    iamrobot,

    Have you figured this out, or do you still need some help?

    Leonard B