| By Bruce Van Horn | Article Rating: |
|
| October 4, 2001 12:00 AM EDT | Reads: |
8,416 |
Q: What's OnRequestEnd.cfm?
A: OnRequestEnd.cfm is the twin brother of Application. cfm. When the code inside a file named Application.cfm is automatically included at the beginning of every .cfm file in the same subdirectory (and any directory below, provided that there isn't another Applic-ation.cfm in those directories), any code placed in a file named On-RequestEnd.cfm is automatically in-cluded at the end of every .cfm page.
Q: I come from an ASP background and am finding certain tasks difficult in ColdFusion. Here's my question: How do I find the size of a file on the server? I've looked everywhere. I have used the FileExists() function, but there really should be a FileSize() function.
A: I agree. There should be a FileSize() function (could be a great user defined function!). The size of a file, however, can be easily (though not intuitively) retrieved using the CFDIRECTORY tag. This tag is usually used for listing the contents of an entire directory or for creating, deleting, or renaming directories, but it can be used to retrieve information about a single file. Here's an example:
<cfdirectory action="LIST"
directory="C:\Inetpub\WWWRoot\
Datafiles"
name="qDir"
filter="AskCFDJ.mdb">
<cfoutput>#qDir.size#</cfoutput>
.
Q: I need to build a form that allows users to upload multiple files to my server. The <input type="file"> tag only allows a single file to be selected. How can I do this?
A: While the HTML <input type="file"> tag only allows you to select a single file, you can use as many of these tags as you like in your form. The trick is to have a CFFILE tag on the action page for every file uploaded. You can accomplish this by naming all of your <input type="file"> tags with similar names, like upload1, upload2, upload3, etc. You can then loop over your form fields to dynamically create the necessary CFFILE tags in your action page. Listing 1 provides an example.
Q: I'm having trouble feeding a quoted list to the IN operator in SQL. I run a query to retrieve certain city names from a database and then use the QuotedValueList() function to turn the results into a quoted list to be used in another query to retrieve only those records in which the cities match the list. My second query looks like this:
<CFQUERY NAME="GetCustomers" DATASOURCE="#dsn#">
SELECT Name, Address1, Address2, City, Phone
FROM Customers
WHERE City IN (#CityList#)
</CFQUERY>
When I look at the list, the city names are there with the appropriate single quotes around each entry (a requirement for the SQL IN operator when querying a text field), . but when I run this query in CF, I get a database error. What am I missing?
A: The problem is that CF automatically "escapes" single quotes inside the CFQUERY tag, so your list actually winds up with two sets of single quotes around each entry. What you need to do is use the Preserve-SingleQuotes() function on your list when you run it in CFQUERY. For example:
<CFQUERY NAME="GetCustoners" DATASOURCE="#dsn#">
SELECT Name, Address1, Address2, City, Phone
FROM Customers
WHERE City IN (#PreserveSingleQuotes(CityList)#)
</CFQUERY>
Q: I really like the ability to create my own functions (UDFs) in CF 5. Is there a place like the Developers Exchange at Allaire.com where I can upload the ones I've written and see what other people have created?
A: Yes. You should visit www.cflib.org, a great source of free UDFs founded by Raymond Camden and Rob Brooks-Bilson.
Please send your questions about ColdFusion (CFML, CF Server, or CF Studio) to AskCFDJ@sys-con.com. Visit our archive site at www.NetsiteDynamics.com/AskCFDJ.
Published October 4, 2001 Reads 8,416
Copyright © 2001 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
Related Links
More Stories By Bruce Van Horn
Bruce Van Horn is president of Netsite Dynamics, LLC, a certified ColdFusion developer/instructor, and a member of the CFDJ International Advisory Board.
























