'coldfusion cffile upload passing a parameter to the action page
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.
Solution 1:[1]
- Wrap the
<cffile>in a function inside a CFC. - Make all of the variables arguments of the function.
- Create the CFC (or put it in the
applicationscope). - 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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Adrian J. Moreno |
