jturkington
asked on
Validating Filename Being Uploaded
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
That is not server side validation and supposing that jaavscript is turned off will not work.
https://www.experts-exchange.com/questions/21403286/display-an-image-outside-of-the-cold-fusion-web-root.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.filecontent
var x = test_array.length;
document.form1.file_name.v
form1.submit();
}
</SCRIPT>
<form action="file_upload.cfm" enctype="multipart/form-da
Enter the file: <input name="filecontents" type="file" size=60>
<input name="file_name" type="hidden"><br><br>
<button onClick=get_name();>Submit
</form>
Page 2 (file_upload.cfm)
------------------------
<!-- compare the file name -->
<cfif variables.filename eq #form.file_name#>
<!-- do something -->
</cfif>