Viewers: in countries Watching now:
In ColdFusion 9 New Features, author and developer Dan Short has gathered together the important updates and improvements in this dynamic web application. Dan showcases the new ColdFusion Builder application throughout the course, using it to work through the new language and CFScript enhancements in this release. He shows how to use the new Server Manager to compare servers and create server groups, as well as monitor server health through notifications. He also explains the new integration with Office applications, building Excel, Word, and even PowerPoint files on the fly from ColdFusion. Finally, he covers the important new Object Relational Mapping feature and how to use the built-in Flash Player. Exercise files accompany this course.
When dealing with file uploads, there have been few options for uploading multiple files at once. You either have to add a group of individual cfinput tags for the file type and deal with each form field individually when the form is submitted or use a third-party component to try and manage the upload process. Many which are hard to use and implement. ColdFusion 9 makes one more hard thing easy by giving us a way to upload multiple files with as little as two lines of code. So, to show that, in the Chapter 8 folder, let's open cffileupload.cfm. I am just going to add one tag onto this page, cffileupload, and I'm going to tell it where to post each of the individual files that get uploaded.
So, we are going to post that cffileupload-uploader.cfm. So, my uploader file is actually going to handle each of the individual form posts. So, for each file that gets uploaded, I will have one form posted at this page. On this page, I will cffile action = ,not upload, but "uploadall". In ColdFusion 8, you would have to use action = "upload" and specify the file field that you want to be uploaded. The action= "uploadall" will take any file field that gets submitted to it and save it to the disk.
So I just need to tell it where to save my file and in this case we're going to save it to the same working directory. We will just use "Expand Path ("."). That's all there is to it. Now that I've written my two lines of code, let's go to the browser and take a look at it. We will go to Chapter8, cffileupload.cfm. My cffileupload tag has embedded this nice- looking Flash control to deal with my file upload. At the top, it shows me which files are going to be uploaded and at the bottom I have a row of buttons to control everything that's going on.
So, I will click Add Files and in the Chapter8 directory, in the assets folder, I am going to choose these two images and just click Select. You can see they get added to the control. I have the File Name, the Size and a progress bar for each. So, let's click Upload and everything goes green. It says it has Uploaded 2 of 2 file(s). That happened really, really fast, because I am on a local connection. On remote connection, these bars would have obviously fill up a little bit slower. Let's go over to CF Builder and make sure that things actually worked.
So, there are a few more things you can change such as whether or not the progress bar shows, the select color. What to do if there is an error and even changing the title of upload control. But sometimes you don't want the Flash uploader. You just want to be able to deal with multiple inputs like you have traditionally. So, in that case, if we go back here, I am going to open up uploadall.cfm. Now, in this file I have my standard ColdFusion 8 way of doing things. I have two CF inputs, one named field1 and one named field2. Now at the top, I have some if statements. If field1 has a value, then run the upload and then dump the result.
If field2 has a value, run the upload and then dump its result. So, let's take a look at this one in the browser. And I will go ahead and choose surf1 for the first one and I will choose surf_woody for the second and click Upload. I need to tell it to overwrite, so let's go back in here and say when there is a name conflict, we want it to overwrite the old file.
Then we will reload our page and we can see we have our two dumps. The first one has surf1.tiff. The second has surf_woody. If I had four other file controls I wanted to add on, I don't want to have to deal with adding more and more of these. So instead, I can just do this. cffile action = "uploadall" and then I want to put the result into my UploadResult variable and then we are going to give it the same nameconflict rules which is to overwrite.
We can get rid of all of this. I will leave that one dump. So, we'll go back to our browser and just Reload. And of course, I forgot to add my destination. So let's add a destination on there. It always helps to know where you want your files to be saved. There we go. Reload once more. And now instead of two individual dumps, I get an array that contains all the information about each individual file upload, so at the first array node, I have surf1.tiff and the second array node, I have surf_woody.jpg.
While the new cffileupload tag may not suit every need for getting multiple files up to your server, it certainly goes a long way to providing a nice clean UI for uploading multiple files in one shot. But whether or not you have used the new Flash upload control, the uploadall attribute of the cffile tag is bound to cut out tons of repetitive coding.
There are currently no FAQs about ColdFusion 9 New Features.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.