System information
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.