?
Solved

Validating Filename Being Uploaded

Posted on 2005-04-26
3
Medium Priority
?
188 Views
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  
</cfif>

Can someone tell me the best way to handle this

Best regards

JT
0
Comment
Question by:jturkington
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
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
http://www.forta.com/books/0321125169/0321125169_pdf.zip

It has an electronic chapter on using the cffile tag.

Of interest is the ClientFile attribute that is exposed.

This may help too:
http://www.edgewebhosting.net/cfdocs/CFML_Language_Reference/2_ColdFusion_Tags/lr2_028.htm
Look under the heading "Evaluating the results of a file upload"
0
 
LVL 8

Expert Comment

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

http://www.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_21403286.html

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
------
<SCRIPT LANGUAGE="JavaScript">
 function get_name() {
  var test_array = document.form1.filecontents.value.split("\\");
  var x = test_array.length;
  document.form1.file_name.value=test_array[x-1];
  form1.submit();
 }
</SCRIPT>

<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>
</form>

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

Expert Comment

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

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