ColdFusion Muse

CSV Files and Coldfusion - a New Approach

Mark Kruger February 5, 2007 12:45 PM Coldfusion Tips and Techniques Comments (32)

Many times we have been tasked with working out a way for an ordinary user to "upload" data into a system. This task is fraught with peril because users are not well versed in the idea of "normalized" data. We've tried the Excel file approach. Excel gives the user so many neat options they can't resist adding formatting, charts, graphs and fiddling with the headers. Even with protected files, clever users find ways to make the data incomplete or unusable. We've also tried access. This is workable but it takes more setup and it requires extra expense on the part of the user (namely, they must have excel). Enter the famed low-tech "csv" or "comma separated value" file.

Read More
  • Share:

Ask-A-Muse: How Do I Use Client Variables?

Muse Reader Asks:
We have a client variables database that is currently storing over 1.5 million records. In the Coldfusion Administrator, client variables are set to purge every 90 days. I was thinking of purging every 7 to 30 days to reduce the number of database entries and hopefully improve performance. What are my options?

It's a good question. Performance depends on many thing including hardware, traffic, tuning, and capacity. Still, 1.5 million rows is a large table and as you might imagine it will perform less ably than a table with just a few hundred thousand rows. Let’s talk about these variables and how they are used.

Read More
  • Share:

Cfinclude vs Cfmodule and Other Things

Mark Kruger January 3, 2007 3:42 PM Coldfusion Tips and Techniques Comments (5)

Muse Reader Asks:
What is the difference between cfmodule, cfinclude? Which one should be used. We have two application.cfm file one at local folder and the other one at the common folder. Which application.cfm will be used when we try to execute Coldfusion template from local directory.

This is really 2 questions so let's take them one at a time. First, let's talk about the difference between Cfmodule and Cfinclude. The first thing to recognize is that that these 2 tags are quite different.

Read More
  • Share:

Ask-a-Muse: Why Don't My Images Display?

Mark Kruger December 15, 2006 2:23 PM Coldfusion Tips and Techniques Comments (9)

Muse Reader Asks:
"When I have subfolders, I have problems displaying images correctly. I tried setting a var called #dir_path# in my application.cfm file (this is actually to differentiate between dev and prod). Then I tried calling my includes and images like so:

<img src="#dir_path#/images/banner.jpg"/>
I know that with the cfinclude, I can't use a physical path, but even if I use a physical path with my images, it doesn't work - I just get a little box with a red "x" in it where my image should be. I've asked another programmer (who is way better than me) about it, and he said he just doesn't use subfolders because of that problem.

First let me say that you may have overestimated your friends programming skills. There is a fundamental difference between using cfinclude and displaying an image. the difference is that one of them has to do with Coldfusion and the other one simply doesn't have anything to do with Coldfusion. Let's review what happens when you load a coldfusion page with an image in it.

Read More
  • Share:

Ask A Muse: Cfinclude Versus Cffile

Mark Kruger December 6, 2006 1:24 PM Coldfusion Tips and Techniques Comments (6)

Muse Reader Asks:
"I am trying to use cfinclude to insert a txt file. But if the txt file has html / of cf code in it, i do not want it to be functional. can the txt file be read as a string?"

You know I love the easy ones. Your problem is misunderstanding the proper use of cfinclude. This tag passes the contents of the included file to the CF parser for execution. It's designed to compile into run time code. What you are trying to do is simply insert the contents of a file into the output buffer (the stuff that goes back to the browser). For that you can use cffile. Cffile will read the contents of your file into a variable - which you may then output onto the page. Here's an example.


<h4>output the contents of myfile</h4>


Notice the use of the expandPath() function. Unlike cfinclude which takes a relative Coldfusion path, cffile needs an absolute path. It needs something that looks like c:\inetpub\wwwroot\blah.txt (or maybe /var/home/www-data/blah.txt on a linux server). ExpandPath( ) is one of those can't-live-without-it functions that allows you to insert the path in a relative fashion.

In your question you indicated that you did not want the HTML to be "functional". I'm not sure what you mean by this - but I suspect you meant that you want the HTML to display on the page like "

" instead of like "this". For that you will need the htmleditformat( ) function as in...
I hope this helps.

  • Share:

Java Based Directory List

This is a follow post to my previous post on cfdirectory as a bottleneck. A helpful muse reader of that post named Daniel Gracia sent me some Java code that builds a directory list. The code itself is a call to the core io.File class. It takes a directory path and returns an array of files and folders mixed (with the folders identified with a period). His claim was that it performed faster than Cfdirectory. His claim is 100% true, but there are some nuances to it. I ran a few tests and here is what I found.

Read More
  • Share:

Variables Scope Memory Leak (say it ain't so)

I just read this fabulous post from Mike Schierberl's blog on Variables Scope Leaking and I thought I would pass it on as a good read. To summarize, it is a common practice to create a component into the application scope and include an "init()" type function in it that returns an instance of itself. For example you might have an "employee" component who's "init()" function takes an employee id as an argument and returns an instance of "employee" populated with user data. That's pretty standard. If you return this new populated instance into the variables scope you would expect the variable to be discarded at the end of the request. Mike's post shows that this does not happen as expected. Because the variables returned are referenced (as apposed to "by value") they persist beyond the request termination.

As a fix you can add structClear(variables) to the end of your request - in the onRequestEnd() function for example. I can't explain it better than Mike. He includes a sample and a flash movie of how he came to his conclusions. It's very thorough.

New Information From Robi Sen

Robi Sen ran his own tests against the SUN JVM. He contests the assertion that this is a Coldfusion issue and he's focused on the JVM. His results may be found

  • Share:

The Infamous "Connector" Scripts and Your Default Document

Flash remoting is supposed to be enabled by default. Indeed, if you set up a web server, add some sites and then install CFMX flash remoting works fine. If, however, you are in the habit of adding new sites to your IIS server that are going to use flash remoting, it may not work. A virtual directory to JrunScripts and some other settings are missing. The fix? Well, one easy "shotgun" approach is simply to run the connector script. It sets things up correctly and remoting starts to work. But (as is often the case) there is a small issue you might run into.

Read More
  • Share: