coldfusion cffile upload passing a parameter to the action page

292 Views Asked by At

In coldfusion I have a basic cffile upload which works fine when the nameconflict parameter is explicit, such as 'overwrite'. But when I try to pass a parameter, it doesn't work.

<cfoutput>
<cfset confl = 'overWrite'>
<form 
  enctype = "multipart/form-data" 
  method  = "post" 
  name    = "uploadForm"  
  action  = "">

   <input name  = "theupload" 
          type  = "file" 
          style = "font-family: comic sans ms; color: ##679C9C">

  <input type = 'hidden' name = 'confl' value = '#confl#'>   
  <cfinclude template = 'submitbut.cfm'>
  </form>
  </cfoutput> 

  <cfif IsDefined("form.theupload")>
  <cfoutput>
   <cffile action = "upload"
    destination   = "#session.exploc#"
    fileField     = "form.theupload"        
    mode          = '666'
    result        = 'ss'
    nameConflict  = "#form.confl#" >

   </cfoutput>
   </cfif>

Is this just the nature of cffile upload? Is there a way to pass a parameter to the action page? The above code is used in several places, and I don't always want the name conflict to be 'overwrite'. I hate to have to use two programs when the only difference is in the name conflict.

1

There are 1 best solutions below

2
On
  1. Wrap the <cffile> in a function inside a CFC.
  2. Make all of the variables arguments of the function.
  3. Create the CFC (or put it in the application scope).
  4. Call the function with the settings correct for each form.

Inside the CFC, do NOT reference session, form, application, request or any other external scoped variables. Only pass data in as arguments to the function. Also, make sure to var or local scope all function specific variables.