View Full Version : cffile upload example limiting upload to .csv files only

November 20th, 2011, 03:57 PM
Here is an example of using ColdFusion to upload a .csv file and only accepting .csv files.

NOTE: You can accept other specific files by changing the "accept" values. For safety and security it is recommended to limit the file upload types to just what you are expecting in your application.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ColdFusion cffile tag example - limiting file upload types</title>

<h2 style="color:Blue">ColdFusion cffile tag example: Upload - accepting only .csv files</h2>

<cfset UploadFolder="D:\home\domain.com\wwwroot\uploads">
<cfif IsDefined("Form.UploadFile") AND Form.UploadFile NEQ "">
accept = "text/csv, application/csv"
The file was uploaded successfully!
<br />
Uploaded file name: <cfoutput>#cffile.ClientFile#</cfoutput>
Select the file that you want to upload:

<form name="UploadForm" method="post" enctype="multipart/form-data" action="">
<input type="file" name="UploadFile">
<input type="submit" name="submit" value="Upload"/>