0

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.

Betty Mock
  • 1,373
  • 11
  • 23
  • 1
    Can you elaborate on "doesn't work"? What "doesn't work"? What behaviour were you expecting, and how did the actual behaviour vary from that? Might be useful to read: http://www.catb.org/~esr/faqs/smart-questions.html – Adam Cameron Apr 08 '22 at 16:22
  • If you dump the form scope do you see the `confl` value? – Dan Bracuk Apr 08 '22 at 17:11
  • @DanBracuk. I did a cfoutput on the confl value before the input hidden statement and got the right number. I did it again after the isdefined form.upload statement and got a blank. I didn't dump the form scope but will try that next. – Betty Mock Apr 10 '22 at 17:49
  • @DanBracuk. I set up a temporary cfm which had the main features in it. When I dumped the form scope everything was all right, and when I tried to substitute my form variable for the name conflict field that also worked. The program I showed in my question is included in a larger program which also has a form, and I think cf got tangled in its skirts as to which form was meant where. – Betty Mock Apr 10 '22 at 20:27
  • @DanBracuk I'm certainly willing to give these forms different names. But strangely, I don't know how to specify which form to use on the action page. Do I replace with – Betty Mock Apr 10 '22 at 20:29
  • If you really need more than one form on a page and they are all posting to the same action page, the action page has to know what form was submitted. I suggest hidden fields such as `fom1`, `form2`, etc. – Dan Bracuk Apr 11 '22 at 12:54
  • @DanBracuk -- not sure what you mean. I do use hidden fields, but how does that distinguish the different forms. I can give each form a name, but I don't know how to reference that name on the action page. Right now I'm trying to do it by using window.open() on the uploads, which would eliminate the double form problem. And maybe present other problems but I'm not there yet. – Betty Mock Apr 14 '22 at 00:41

1 Answers1

-2
  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.

Adrian J. Moreno
  • 14,350
  • 1
  • 37
  • 44
  • Mine is the second downvote. I don't see how this answer solves the OP's problem. Feel free to explain it though. – Dan Bracuk Apr 09 '22 at 04:05
  • True it doesn't answer the initial question, but it does address the latter issue of wanting to avoid repeating the same code in multiple places. – SOS Apr 12 '22 at 21:58