Adobe
產品
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
更多產品
解決方案
數位行銷
數位媒體
教育機構
金融服務業
政府機關
網頁體驗管理
更多解決方案
教學 說明 下載 公司
購買
家庭使用 適用於個人和家庭辦公室
授權方案 適用於企業、學校和政府機關
其他購買方式
搜尋
 
資訊 登入
歡迎, 我的購物車 我的貨品 我的客戶支援
我的帳戶
登出
為何要登入?登入即可管理您的帳戶並取得試用下載、產品擴充功能、社群討論區等。
Adobe
產品 產業 購買   搜尋  
解決方案 公司
說明 學習資源
登入 登出 我的貨品 我的客戶支援
Date Date
Qty:
Subtotal
Checkout
開發人員中心 / Dreamweaver 開發人員中心 /

Creating a ColdFusion upload page in Dreamweaver CS4

作者 Raymond Camden

Raymond Camden
  • coldfusionjedi.com

Created

12 December 2008

頁面工具

在 Facebook 上共用
在 Twitter 上共用
在 LinkedIn 上共用
書籤
列印

Tags

系統需求

必須具備的知識

Familiarity with Dreamweaver and ColdFusion.

使用者等級

中級

要求的產品

  • 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 an event registration application in PHP – Part 2: Building the back end
  • Setting up a ColdFusion development environment for Dreamweaver
  • Setting up a PHP development environment for Dreamweaver
  • Setting up an ASP development environment for Dreamweaver
  • Which server-side technology should I choose?
  • Creating your first website – Part 6: Publishing your website
  • Setting up a local testing server in Dreamweaver CS5
  • Building your first dynamic website – Part 1: Setting up the site and database
  • Building your first dynamic website – Part 2: Developing the back end
  • XML 概觀

產品

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • 行動應用程式
  • Photoshop
  • Touch Apps

解決方案

  • 數位行銷
  • 數位媒體
  • 網頁體驗管理

產業

  • 教育機構
  • 金融服務業
  • 政府機關

說明

  • 產品說明中心
  • 訂購與退貨
  • 下載與安裝
  • 我的 Adobe

學習資源

  • Adobe Developer Connection
  • Adobe TV
  • 培訓與認證
  • 論壇
  • 設計中心

購買方式

  • 適用於個人和家庭辦公室
  • 授權方案
  • 其他購買方式

下載

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

公司

  • 新聞室
  • 合作夥伴方案
  • 企業社會責任
  • 工作機會
  • 投資者關係
  • 事件
  • 法律聲明
  • 安全性
  • 聯絡 Adobe
選擇您所在的國家/地區 台灣 (變更)
選擇您所在的國家/地區 關閉

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.

使用條款 | 隱私權政策和 Cookies (更新)