Is there an easy way to run an Ajax function from <input type=file> to test the file name in DB?
I've had the <input type="file"> ... <cffile ...> thing going for a few years now.
There is a database where the uploaded file names are stored once the files are uploaded to the server. It sees things in terms of problems and stores uploaded file name accordingly with the ProbID prepended onto the file name; e.g., MyPicture.jpg would end up in the designated directory and databawe as P416_MyPicture.jpg. This allows user to store pictures with the same name in different problems without a conflict. There has been an issue with certain characters (e.g., spaces, +, #, etc.) causing problems when they are in file names so we have come up with a way using the <cffile ... rename> to replace these chars with _. This means that MyPic+.jpg would end up being P416_MyPic_.jpg.
This is where the problem appears. If someone were to upload MyPic+.jpg after someone else uploaded MyPic_.jpg in the same problem, then the + file would overwrite the _ file before the system knew they had a problem. And there is now way to restore the original file without going to the system backup and doing so – which is a whole other story … especially, if the person doesn’t tell anyone.
The logical solution would be to be able to test the new final file name (the name after making the substitutions mentioned above) against the existing files in the database before you went from the page where the <input type=file> control to the associated _action.cfm page where the <cffile> object is located. Given that this seems to be the province of Ajax, this would seem like a natural use of the really interesting technology. I have can determine the file name from the onChange action on the <input type=File> so that this would be the place for Ajax to come to the rescue by looking up the final file name and then letting the user know whether the resultant name is a unique within the database or not. If so, I'll just enable the Add button which sets right next to the <input > control and let them upload it. If not, I'll put up an error message telling them that this file already exists in the system.
This would be the perfect solution. It would let me do some Ajax stuff like I've wanted to do for the past year, but never have had the time to do because this is the project that won't go away. This is, in fact, the last thing of any consequence that remains to do on this 2-1/2 year nightmare – be careful what you wish for. If I can get this done this week, then maybe I can finally take a weekend off … maybe it will finally come to an end.
Which finally leads to my question: I'm looking for some tips on how to get this thing going since I can barely spell Ajax. I've got a book and looked at some stuff online about CF and Ajax, but a good example or two or three would be worth a day's worth of poking around on the web and in my books.
Thanks in advance for any suggestions, ideas, help, whatever.
:-}
Len
