Upload Files to Directory

Submitted by:Jhon Jhon

Date added:03 August, 2013

Category:ColdFusion

ColdFusion code for upload files to directory

Tags: upload

Code Snippet:

    <cfset startDir = "C:\">
<cfset newDir = startDir & replace(Form.Listing, " ", "_", "All")>
<cfdirectory directory="#newDir#" action="CREATE" >
<cfset aResults = StructFindKey(#Form#, "FiletoUpload-0", "all")>
<!---<cffile action="upload"
destination="#newDir#"
nameConflict="overwrite"
fileField="Form.FiletoUpload-0">--->

<body>
<cfoutput>
<cfloop collection = #Form# item = "forms">
<tr>
<td>#StructFind(Form, forms)#</td>
</tr>
</cfloop>
<p>Your directory #newDir# has been created</p>
<p>Your file has been uploaded</p>
</cfoutput>
<cfdump var="#aResults#">
</body>
</html>
<cfif StructKeyExists(Form, "fieldnames")>
<cfloop list=#form.fieldnames# index="i">
<cfif FindNoCase("FiletoUpload-",i) AND Len(form[i])>
<cffile action="upload"
destination="#newDir#"
nameConflict="overwrite"
fileField="#i#"
result="ThisFile">
</cfif>
</cfloop>
</cfif>
 
 

Comments