Quackit Logo
HTML
CSS
Scripting
Database
Hosting
Design
XML
IMCreator - Free Website Builder

Using cffile Parameters

The previous lesson showed the parameters that are available to developers when the cffile tag is used to upload a file to the server.

These parameters are available in the 'file' scope and can be used in a number of ways.

One common technique is to insert some/all of these parameters into a database. If you do this, later on you can use the database to lookup the details of any file that has been uploaded to the server. This can be useful if you want to dynamically render details about the file to the user.

For example, you could use the 'serverFileExt' parameter to display the appropriate icon (i.e. Word icon, PDF icon etc). You could also use the 'fileSize' parameter to display the file size to the user. This is good usability practice - especially if the file is large. You could even create an image library for users to browse images and view their details if you wish.

In the following example, I have modified the code from the file upload lesson so that we are now inserting details about the file into a database. This, of course, assumes you have a database configured with the appropriate datasource/tables/columns etc

<cfif isDefined("fileUpload")>
  <cffile action="upload"
     fileField="fileUpload"
     destination="C:\docs"
     nameconflict="makeunique">


<cfquery datasource="dsn">
insert into FileUploadInfo (
	ClientDirectory,
	ClientFile ,
	ClientFileExt,
	ClientFileName,
	ContentType,
	ContentSubType,
	FileSize,
	ServerDirectory,
	ServerFile,
	ServerFileExt,
	ServerFileName
) values (
	'#file.clientdirectory#',
	'#file.clientfile#',
	'#file.clientfileext#',
	'#file.clientfilename#',
	'#file.contenttype#',
	'#file.contentsubtype#',
	#file.filesize#,
	'#file.serverdirectory#',
	'#file.serverfile#',
	'#file.serverfileext#',
	'#file.serverfilename#'
)
</cfquery>

     <p>Thankyou, your file has been uploaded.</p>
</cfif>
<form enctype="multipart/form-data" method="post">
<input type="file" name="fileUpload" /><br />
<input type="submit" value="Upload File" />
</form>

Enjoy this page?

  1. Link to this page (copy/paste into your own website or blog):
  2. Link to Quackit using one of these banner ads.

Thanks for supporting Quackit!