It’s easy uploading files to your server over the web with Coldfusion. Follow these easy steps to accomplish this task.
We will create 1 page that will do it all for us.Create a new page in Ultradev and save it as “uploadfile.cfm”.
Create a normal form with a file field.
<form action=”uploadfile.cfm” method=”POST” name=”frmupload” enctype=”multipart/form-data”>
<input type=”file” name=”file_path”>
<input type=”submit” name=”submit_upload” value=”upload”>
</form>
We will send the form to the same page and perform the upload here too. Add the following code above the <form> tag we just created:
<cfif isdefined(“form.submit_upload”)>
<cffile action=”UPLOAD” filefield=”file_path” destination=”C:\Documents and Settings\Administrator\Desktop” nameconflict=”MAKEUNIQUE“>
File Uploaded!
</cfif>
Take a look at the full code:
enctype: The content type “multipart/form-data” should be used for submitting forms that contain files, non-ASCII data, and binary data.
filefield: You should use the name of the file form element from your upload form.
destination: Should contain the physical path to the directory on the server where you want the file to be uploaded.
MAKEUNIQUE: This value forces Coldfusion to create a unique name for the uploaded file if it encounters the same name |