Validating Filename Being Uploaded

Posted on 2005-04-26
Medium Priority
Last Modified: 2013-12-24
I am still learning the concept of file uploads. Can someone show me in the right direction on this one.

I have a unique variable on the page called VARIABLES.Filename (DOC001.doc etc..) that i need to compare with the filename being uploaded with the input file field.

I need to perform some server side validation such as

<cfif VARIABLES.Filename NEQ filename?????>
         Filename being attached doesn't match DOC001.doc  

Can someone tell me the best way to handle this

Best regards

Question by:jturkington
  • 2
LVL 35

Accepted Solution

mrichmon earned 2000 total points
ID: 13867729
Well you have to upload the file first to be able to do the comparison - then delete if it isn't valid.

This may be helpful

It has an electronic chapter on using the cffile tag.

Of interest is the ClientFile attribute that is exposed.

This may help too:
Look under the heading "Evaluating the results of a file upload"

Expert Comment

ID: 13870405
I just answered almost the same question a few minutes ago. Here is the link to that question.


Basically, what you want to do is grab the file name as the page is being uploaded, and then compare that on the next page.

Here is the code again (modified for your question):

Page 1
 function get_name() {
  var test_array = document.form1.filecontents.value.split("\\");
  var x = test_array.length;

<form action="file_upload.cfm" enctype="multipart/form-data" method="post" name=form1>
 Enter the file: <input name="filecontents" type="file" size=60>
 <input name="file_name" type="hidden"><br><br>
 <button onClick=get_name();>Submit</button>

Page 2 (file_upload.cfm)
<!-- compare the file name -->
<cfif variables.filename eq #form.file_name#>
 <!-- do something -->
LVL 35

Expert Comment

ID: 13870444
That is not server side validation and supposing that jaavscript is turned off will not work.

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question