As it is my job to continue educating myself on topics related to my position, I continue to learn new things to make my life a little easier. A few weeks ago we ran across an issue that had cropped up regarding downloadable documents. Since a number of our websites have upload areas, whether it be for interactive media and video, it had the potential for opening up areas that could be used maliciously, had the problems not been fixed. One of the solutions was to not have a direct link to the file, but to present the file through Coldfusion by using cfcontent and cfheader. For most situations this would prompt the browser to do whatever it does when dealing with files. Some will be opened in the window and some will be prompted for a save. Usually it’s all about what the user’s settings are, unless of course we use a mime type to force the download, but that’s another story entirely.
What I found was a simple little item that most people wouldn’t really think about, but it’s actually quite handy. When you’re downloading a file, especially large files, you sometimes get a little dialog box that shows how long the download is going to take. For some of the files we have available for download, the size is actually quite large, and seems even larger as you sit staring at the computer “Is it done yet?” but there’s no time elapse taking place. Why not? Well, the download doesn’t know how big the file is. All this interactive websites stuff conveniently forgets that people still have to sit around and wait for some things, and that our browsers provide some information, if we provide information to it. So, what I found was a simple line of code that will tell the browser how big the file is, and in turn, it can figure out how long the download takes and the percentage of completion.
And here it is:
<cfheader name=“content-length” value=“#getFileInfo(pathandfileName).size#” />
This simple line uses the Coldfusion function getFileInfo to return the size of the file (duh). All we have to do is pass in the path of the file, which in the case of a downloadable document we already have. The getFileInfo function of course also provides a bunch of other information about a file, in structure format. Before where we may have had to separate out the path and filename so that the download file name (the name that it would get saved as) would show up, instead we can just use the getFileInfo to return the name of the file itself. It’s a pretty nifty tag.