Exercise 7: Validating the existence of the trip photo file
121
For more information about the
FileExists
function, see
CFML Reference.
To verify that the photo filename exists:
1.
Open the tripeditaction.cfm file in the my_app directory.
2.
Add logic to check that the user entered a valid photo filename by copying the following code
immediately following the first
<cfset isOk = "Yes">
statement:
<!-- Check to see if photo file exists. --->
<cfset PhotoLocation =
"C:\Inetpub\wwwroot\CFDOCS\getting_started\Photos\">
<cfset PhotoLocation = PhotoLocation & FORM.photo>
<cfif not FileExists(PhotoLocation)>
<cfset isOk = "No">
<cfoutput>Trip Photo does not exist</cfoutput>
</cfif>
3.
Verify that the code you just copied is pointing to the correct PhotoLocation path. The path is
specified in the
<cfset PhotoLocation = "C:...">
tag.
For example, depending on your web server configuration, the PhotoLocation path might be:
■
For MS Windows systems:
<cfset PhotoLocation =
"C:\CFusionMX7\wwwroot\cfdocs\getting_started\photos\">
or
<cfset PhotoLocation =
"C:\Inetpub\wwwroot\cfdocs\getting_started\photos\">
■
For Linux or Solaris systems:
<cfset PhotoLocation =
"/opt/cfusionmx7/wwwroot/cfdocs/getting_started/photos/">
or
<cfset PhotoLocation =
"/<webserverdocroot>/cfdocs/getting_started/photos/">
4.
Save the file.
To test the modified code:
1.
View the tripedit.cfm page in your browser.
2.
Perform tests by doing the following:
a
In the Trip Edit page, enter valid information in all the required fields except the Photo
Filename field.
b
In the Photo Filename field, enter
nowhere.jpg,
and click Save.
The following error message appears: Trip photo does not exist.
c
To avoid the error, replace the invalid photo filename in the Trip Edit page with
somewhere.jpg
and click Save.
The following message appears: Trip added.
Summary of Contents for COLFUSION MX 7-GETTING STARTED BUILDING COLDFUSION...
Page 1: ...COLDFUSION MX7 Getting Started Building ColdFusion MX Applications...
Page 6: ...6 Contents...
Page 10: ......
Page 14: ...14 Chapter 1 Introducing ColdFusion MX...
Page 38: ...38 Chapter 3 Database Fundamentals...
Page 40: ......
Page 58: ...58 Chapter 5 Lesson 2 Configuring Your Development Environment...
Page 70: ...70 Chapter 6 Lesson 3 Retrieving Data...
Page 84: ...84 Chapter 7 Lesson 4 Building Dynamic Queries...
Page 96: ...96 Chapter 8 Lesson 5 Creating a Trip Detail Page...
Page 102: ...102 Chapter 9 Lesson 6 Creating a Main Application Page...