Uploading files in Coldfusion is very easy and we are going to go through the code required for it.
First off create a folder in your directory, in our case we have called it 'files' but it can be anything.
upload.cfm
Code:
<cfset uploadPath = left(getDirectoryFromPath(GetBaseTemplatePath()),len(getDirectoryFromPath(GetBaseTemplatePath()))) & '/files/' >
The above code needs to go at the top of the upload.cfm page above the 'DOCTYPE' / <HEAD> tags. This code just files the directory for uploading so we want files and show above as: '/files/'
upload.cfm
Code:
<form enctype="multipart/form-data" method="post">
<input type="file" name="fileupload" /><br />
<input type="submit" value="Upload it" />
</form>
Above is the required code for your form and can be placed any where on your page, BUT the code below is best to go above this code when you get to it.
upload.cfm
Code:
<cfif isDefined("fileupload")>
<cffile action="upload"
filefield="fileupload"
nameconflict="overwrite"
destination= "#uploadPath#" >
<cfoutput>
<p>Upload Complete!</p>
File size: #file.FileSize#<br />
File extension: #CFFILE.ServerFileExt#<br />
File name: #file.SERVERFILE#<br />
File location: #file.ServerDirectory#
</cfoutput>
</cfif>
The above code will upload any file to the 'files' folder, it will then show the file information such as file size, file extension, file name and the location.
If the attached Zip file which you can download and view the source code as some gif's in the files folder just in case you dont have any to play with
Have fun uploading!