Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Dreamweaver Developer Center /

Creating a ColdFusion upload page in Dreamweaver CS4

by Raymond Camden

Raymond Camden
  • raymondcamden.com

Created

12 December 2008

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
client-server ColdFusion 8 Dreamweaver CS4 dynamic website extensibility file management

Requirements

Prerequisite knowledge

Familiarity with Dreamweaver and ColdFusion.

User level

Intermediate

Required products

  • Dreamweaver (Download trial)
  • ColdFusion (Download trial)

File upload pages allow users to select files from their local hard drive and upload them to a server through a web browser. Building a file upload page with ColdFusion is quick and easy using the upload action of the CFFILE tag. CFFILE is a ColdFusion tag that can perform a variety of file management–related actions such as reading, writing, moving, renaming, and uploading files.

For the purpose of this article, I will focus on the upload action of this tag and provide Dreamweaver CS4 instructions for creating a simple ColdFusion file upload page. Although the step-by-step instructions provided in this article pertain to the Dreamweaver interface, the resulting code, which is listed at the bottom of this page, can be customized for use in other editors as well. The ColdFusion code used in the file upload example will work with versions 5 and above of ColdFusion Server.

Note: Adobe Dreamweaver Exchange lists the latest extensions available for download. In addition to the method provided in this article, you may also want to visit the Exchange to search for related extensions.

Protecting server security

Allowing file uploads can potentially compromise server security. For this reason, it is a good idea to evaluate possible risks before implementing file uploads in a web application. There is no foolproof way to ensure a secure file upload in a web application, although through careful design, it is possible to reduce your risk.

Some suggestions for protecting server security:

  • Carefully choose the directory to which the files are to be uploaded. Files should be uploaded to a location on the server that will not conflict with existing application or system files.
  • Restrict upload for file extensions that can potentially be dangerous: .cfml, .cfm, .php, .bat, .exe and so on.
  • Authenticate users before allowing them to upload files.

Note: For additional information about server security, refer to Security Best Practice: Evaluating the Risks of Allowing Uploading and of Attached Files on Your Server (TechNote 17618).

Building the HTML form

The following steps provide instructions on how to create the HTML form. This simple HTML form will be the interface through which users select and upload files.

  1. Create a new ColdFusion document and save it within a defined site that has been configured to handle ColdFusion content. Name this page cf_upload.cfm and change the title from Untitled Document to Upload File with ColdFusion.

    Note: For more information about defining a site, refer to Setting up a site in Dreamweaver CS4 / Setting up a site in Dreamweaver CS5 in Dreamweaver Help.

  2. Select Insert > Form or drag a form button onto the page by clicking and dragging the Form icon in the Forms tab of the Insert bar.
  3. Select the form using the tag selector or by clicking the red dashed line. If you do not see the red dashed line turn on the Invisible Elements (View > Visual Aids > Invisible Elements).
    • In the Property inspector of the form, enter upload_form in the Form Name field.
    • In the Action field, enter cf_upload.cfm.
    • Switch the method from Get to Post.
    • In the Enctype field, select multipart/form-data.
    • Change to code view (View > Code), the code should now look like the example below:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Upload File with ColdFusion</title> </head> <body> <form action="cf_upload.cfm" method="post" enctype="multipart/form-data" name="upload_form"></form> </body> </html>
  1. Create an insertion point within the form by clicking inside the red dashed line and choose Insert > Form Objects > File Field. It's also possible to add form objects to the page by dragging them from the Forms tab of the Insert bar. Just click and drag the form object to the desired location within the form tag.
  2. Select the file field you just inserted and enter ul_path in the File Field Name of the Property inspector.
  3. Add a button form object to the page using one of the methods described in Step 4.
  4. Select the button and enter upload_now in the Button Name field of the Property inspector. Set the Action property to Submit form.

Here is the completed HTML form code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Upload File with ColdFusion</title> </head> <body> <form action="cf_upload.cfm" method="post" enctype="multipart/form-data" name="upload_form"> <input type="file" name="ul_path" id="ul_path" /><input name="upload_now" type="submit" value="Submit" /> </form> </body> </html>

Adding the ColdFusion file upload functionality

Now that the HTML form is ready to go, you can add a few lines of CFML code using the Dreamweaver interface:

  1. Choose Code view using the View menu (View > Code) or by clicking the Code icon in the document toolbar.
  2. Place your cursor after the <body> tag and press Enter once to create a blank space.
  3. Select the CFML Flow tab of the Insert bar and click the cfif button to insert the CFIF tag.
  4. In the Code view pane click before the final bracket of the opening CFIF tag and enter:
isdefined("form.upload_now")

Your CFIF tag should now match the code below:

<cfif isdefined("form.upload_now")></cfif>
  1. Click between the opening and closing CFIF tags and press Enter twice to create a blank line. With your cursor at the beginning of this new line, click the CFFILE icon in the CFML Advanced tab of the Insert bar.
  2. In the Cffile dialog box, enter the following values (see Figure 1):
    • Action: Choose Upload from the Action list menu.
    • File Field: Enter the name of the File Field form object ul_path.
    • Destination Path: Enter the absolute path to the directory in which the files will be uploaded. The path you enter depends on the location of the directory in which the files will be saved on the server.

    Note: On Unix systems, make sure that the upload path directory is configured with the correct permissions so file upload can write to that directory. Normally, this directory would be owned by the ColdFusion user or the account that runs the web server.

    Note: On Mac OS X systems, if you end up with a path with colons (:) in it—for example, Macintosh HD:Users:ray:Documents:Web Sites:webroot:cfuploaddwarticle—replace colons with forward slashes: /Users/ray/Documents/Web Sites/webroot/cfuploaddwarticle.

    • Accept Files: List the mime types and file types that you will accept separated by commas. For this example, only GIF and JPG image files will be accepted, so enter: image/gif,image/jpeg.
    • Filename Resolution: The option selected in this field determines what will happen if the name of the file to be uploaded already exists on the server. All available options are listed below:
      • Error: The file will not be uploaded and ColdFusion will stop processing the page and return an error.
      • Skip: The file is not uploaded and no error message is displayed.
      • Overwrite: Files with the same name are overwritten.
      • Makeunique: The file is uploaded and given a unique name. In this example, Makeunique is chosen for Filename Resolution.
The Tag Editor - cffile dialog box, with values filled in.
Figure 1. The Tag Editor - cffile dialog box, with values filled in.
  1. After completing this dialog box, click OK.
  2. Between the closing bracket of the CFFILE tag and closing CFIF tag, type in a message to be displayed when a file has been uploaded. For example:
<cfif isdefined("form.upload_now")> <cffile accept="image/gif,image/jpg,image/jpeg" action="upload" destination="/Users/ray/Documents/Web Sites/webroot/cfuploaddwarticle" filefield="ul_path" nameconflict="makeunique"> Thanks for uploading a file! </cfif>

The complete code is listed below:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Upload File with ColdFusion</title> </head> <body> <cfif isdefined("form.upload_now")> <cffile accept="image/gif,image/jpg,image/jpeg" action="upload" destination="/Users/ray/Documents/WebSites/webroot/cfuploaddwarticle" filefield="ul_path" nameconflict="makeunique"> Thanks for uploading a file! </cfif> <form action="cf_upload.cfm" method="post" enctype="multipart/form-data" name="upload_form"> <input type="file" name="ul_path" id="ul_path" /> <input name="upload_now" type="submit" value="Submit" /> </form> </body> </html>

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License

More Like This

  • Creating a multiscreen theme for WordPress using Dreamweaver CS5.5
  • Dreamweaver CS5 Missing Manual excerpts: Behaviors, site management, and templates
  • Building Drupal Zen subthemes with Dreamweaver CS4
  • Creating master and detail ColdFusion pages
  • Creating user-defined functions for ColdFusion 8 in Dreamweaver CS4
  • Creating custom server behaviors and Dreamweaver extensions
  • Managing multiple subscriptions in PHP
  • Building a subscribe/unsubscribe app in PHP with Dreamweaver CS3
  • Building a photo album with the Spry framework
  • Creating and consuming ColdFusion components and web services with Dreamweaver CS4

Tutorials and samples

Tutorials

  • Understanding HTML5 semantics: Changed and absent elements
  • Mobile app with PhoneGap: Submitting to the Apple App Store
  • PhoneGap and Dreamweaver: Releasing on iOS
  • Mobile app with PhoneGap: Submitting to Android Market

Samples

  • Responsive design with jQuery marquee
  • Customizable starter design for jQuery Mobile
  • Customizable starter design for HTML5 video
  • Customizable starter design for multiscreen development

Dreamweaver user forum

More
04/23/2012 Resolution/Compatibility/liquid layout
04/20/2012 using local/testing server with cs5 inserting images look fine in the split screen but do not show
04/18/2012 Ap Div help
04/23/2012 Updating

Dreamweaver Cookbook

More
11/07/2011 Simple social networking share buttons
09/20/2011 Registration form that will generate email for registrant to validate
08/21/2011 Spry Accordion - Vertical Text - Auto Start on Page Load - Mouse Over Pause
08/17/2011 Using cfdump anywhere you like

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement