MACROMEDIA COLDFUSION MX 61-GETTING STARTED BUILDING COLDFUSION MX Getting Started page 107

Building coldfusion mx applications
Table of Contents

Advertisement

You used the
required
Now you must make sure that the file exists in the right directory so the application can display it
to customers.
Since browser clients are prohibited from doing standard file I/O (input/output) on the web
server, the Trips Maintenance application will use server-side validation to ensure the existence of
the photo file. You will add the business rule for the photo file to the tripeditaction.cfm page.
To check to see if a file exists, ColdFusion provides a
function is:
FileExists(absolute_path)
This function returns True if the file specified in the argument does exist; otherwise, it returns
. Assume that a data entry page has an input tag named "testFileName". If a user types in a
False
valid filename, the action page snippet from the following example would display the message
"The test file exists":
<cfset fileLocation = "c:\inetpub\wwwroot\images\">
<cfif IsDefined("form.testFileName")>
<cfif form.testFileName is not "">
<!---Concatenate the File Location with the FileName passed in--->
<cfset fileLocation = fileLocation & form.testFileName>
<cfif FileExists(fileLocation)>
<cfoutput> The test file exists. </cfoutput>
</cfif>
</cfif>
</cfif>
Note: The trip photo images are stored in the following path relative to your web root directory:
\cfdocs\getting_ started\photos. Therefore, if your web root is C:\inetpub\wwwroot, then the photos
are stored in the C:\inetpub\wwwroot\cfdocs\getting_ started\photos directory.
For more information about the
Reviewing the code
The following table describes the code used to verify whether a file exists:
Code
<cfif
IsDefined("form.testFileName")>
<cfset fileLocation = fileLocation
& form.testFileName>
<cfif FileExists(fileLocation)>
Exercise: use FileExists function to verify the existence of photo filename
In this exercise, you will use the Cold Fusion
filename entered in the Trip Edit page exists in the location specified.
attribute for the photo
FileExists
Explanation
The
cfif
has been entered.
The ColdFusion
original value for
("c:\inetpub\wwwroot\images\") with the value of the
testFileName
FileExists checks to see if the file indicated by the
fileLocation
FileExists
Developing code to validate data and enforce business rules
tag to ensure that a filename is entered.
cfinput
function. The syntax of this
FileExists
function, see CFML Reference.
tag checks to see if the form variable
operator in the
&
fileLocation
form variable.
variable exists at the specified disk location.
function to ensure that the photo
testFileName
tag combines the
cfset
from the first source line
107

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION MX 61-GETTING STARTED BUILDING COLDFUSION MX and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Coldfusion mx

Table of Contents