Upload files with Coldfusion

Learn how to upload files from a web browser to your server.
 

 

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. back

filefield: You should use the name of the file form element from your upload form.back

destination: Should contain the physical path to the directory on the server where you want the file to be uploaded.back

MAKEUNIQUE: This value forces Coldfusion to create a unique name for the uploaded file if it encounters the same name.back

Happy Programming!
omar
http://www.udnewbie.com

 

Omar Elbaga

Starting out as a fine artist, Omar Elbaga gradually moved to computer graphic arts. He was particularly amazed by the power of the World Wide Web, so he embarked upon building small-scale sites for fun utilizing HTML and his Art background. Falling in love with designing web pages and its potential, he began a career in web design. Omar has since been in the web development field for several years. With his head in computer books nearly 24 hours a day, Omar moved on to enhance his skills from web design to web programming.

Most of his work involves building database-driven web sites for small companies. Omar is currently running a popular Dreamweaver MX resource site named dmxfire.com

See All Postings From Omar Elbaga >>

Comments

Be the first to write a comment

You must me logged in to write a comment.