![]() ![]() ![]() |
||
|
At this point, you have a more efficient application. The client is handling much of the validation of the Compass Travel new trip business rules. Except for the trip photo file, the server receives only valid data.
The trip photo file business rule does not fit nicely into this design, however. This business rule has two parts:
You used the required
attribute for the photo cfinput
tag to ensure that a filename is entered. Now you must ensure that the file exists in the right directory so that the application can display it to the user.
Because browser clients are prohibited from doing standard file input and output (I/O) on the web server, the Trip Maintenance application uses server-side validation to ensure the existence of the photo file. You add the business rule for the photo file to the tripeditaction.cfm page.
To verify that a file exists, ColdFusion provides a FileExists
function. This function has the following syntax:
FileExists(absolute_path)
This function returns Yes if the file specified in the argument does exist; otherwise, it returns No.
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, the photos are stored in the C:\inetpub\wwwroot\cfdocs\getting_ started\photos directory.
For more information about the FileExists
function, see CFML Reference.
<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>
<cfset PhotoLocation = "C:...">
tag.
For example, depending on your web server configuration, the PhotoLocation path might be:
<cfset PhotoLocation =
"C:\CFusionMX7\wwwroot\cfdocs\getting_started\photos\">
or
<cfset PhotoLocation =
"C:\Inetpub\wwwroot\cfdocs\getting_started\photos\">
<cfset PhotoLocation =
"/opt/cfusionmx7/wwwroot/cfdocs/getting_started/photos/">
or
<cfset PhotoLocation =
"/<webserverdocroot>/cfdocs/getting_started/photos/">
The following error message appears: Trip photo does not exist.
The following message appears: Trip added.
The following table describes the code used to verify whether the photo file exists:
Code |
Explanation |
---|---|
<cfset PhotoLocation = "C:\CFusionMX7\wwwroot\cfdocs\ getting_started\photos\"> |
The Note: The code snippet shows one value for Windows systems. |
<cfset PhotoLocation = PhotoLocation & FORM.photo> |
The ColdFusion |
<cfif not FileExists(PhotoLocation)> <cfset isOk = "No"> <cfoutput> Trip Photo does not exist. </cfoutput> </cfif> |
|
|
||
![]() ![]() ![]() |