Simple Coldfusion Upload Script
This tutorial will take you through the basics of creating a simple Coldfusion upload script. This script is ideal for uploading any file types. I will later be adding a tutorial on advanced file uploading with file type validation and size limiting.
To create an upload script the first thing we need is a form to select the file, so here is a quick example of a simple form with a file field and a submit button that submits to the current page.
<form action="<cfoutput>#CurrentPage#" method="post" enctype="multipart/form-data" name="Upload" id="Upload"></form>
<input type="file" name="File"/>
<input type="submit" name="Upload" value="Upload"/>
With that form created we will then need to create the script to handle the form and to upload the file, and this being Coldfusion they couldn't have made it easier for us.
<cffile action="upload" destination="D:\Domains\cfproject.co.uk\wwwroot\ColdfusionSamples\upload" filefield="FORM.File" nameconflict="overwrite">
File Uploaded!
</cfif>
Here we have a very simple script that just checks to see if the form has been submitted then using the cffile tag it uploads that file to the destination directory. In this tutorial i have set the conflict to overwrite, but you could also have error, skip or makeunique.
This should be what you full file looks like.
<cffile action="upload" destination="D:\Domains\cfproject.co.uk\wwwroot\ColdfusionSamples\upload" filefield="FORM.File" nameconflict="overwrite">
File Uploaded!
</cfif>
<cfset CurrentPage=GetFileFromPath(GetTemplatePath())>
<form action="<cfoutput>#CurrentPage#" method="post" enctype="multipart/form-data" name="Upload" id="Upload">
<input type="file" name="File"/>
<input type="submit" name="Upload" value="Upload"/>
</form>

