Skip to main content
April 4, 2011
Question

CFFile action="uploadall" question

  • April 4, 2011
  • 1 reply
  • 3420 views

I am doing a cffile uploadall process and I want to return a list/array of filenames uploaded.  It doesn't seem like it should be too hard - should it?

Thanks.

    This topic has been closed for replies.

    1 reply

    Inspiring
    April 4, 2011

    Take a look at the CF documentation.  It states: After a file upload is completed, this tag creates an array of structures specified by the result parameter. Each structure in the array contains upload result information for one file. For information on the result structure contents, see cffile action = "upload".

    http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7388.html

    April 4, 2011

    Here's my code:

    Upload page -

    <cffileupload
    hideuploadbutton="no"
    progressbar= "no"
    stoponerror="yes"
    title="Upload Closeout Pictures"
    url="process.cfm?pro_num=#pro_num#&type=#urlencodedformat(form.type)#"
    wmode="transparent"
    maxfileselect=6 />

    <cfif isDefined("myImage.serverfile")>
          wow
    <cfelse>
          hey
    </cfif>

    Processing page -

    <cffile
    action="uploadall"
    destination="#path#"
    nameconflict="overwrite"
    result="myImage" />

    I get nothing in the myImage variable.

    Inspiring
    April 7, 2011

    Upload.cfm

                    <cffileupload

                    hideuploadbutton="no"

                    progressbar= "no"

                    stoponerror="yes"

                    title="Upload Closeout Pictures"

                    url="process.cfm?pro_num=#pro_num#&type=#urlencodedformat(type)#"

                    wmode="transparent"

                    maxfileselect=6 />

    Process.cfm

                    <cfset path = #file_path# & "\" & #url.pro_num# >

                    <cffile

                    action="uploadall"

                    destination="#path#"

                    nameconflict="overwrite"

                    result="uploadedFiles" />

                    <!--- iterate over uploadedFiles result array and perform an insert for each record --->

                    <cfif IsDefined("uploadedFiles") and IsArray(uploadedFiles) and ArrayLen(uploadedFiles) gt 0>

                    <cfloop from="1" to="#ArrayLen(uploadedFiles)#" index="idx">

                                    <cfset name = "pic" & idx>

                                    <cfquery name="insertFileRecord" datasource="#application.dsn#">

                                                    update closeout set #name# = '#uploadedFiles[idx].serverfile#'

                                                   where pro_num = '#url.pro_num#' and type = '#url.type#'

                                    </cfquery>

                    </cfloop>

                    </cfif>


    Since uploadall acts asynchronously a separate call to process.cfm might be made for each file uploaded. This would result in the name variable being equal to "pic1" for every file uploaded.