Dave,

Someone else here posted this JavaScript code for checking the file type
within the browser.  This combined with server side checking validation
should help prevent people from uploading the wrong file type.  I use it for
all my image upload routines. The customers like being warned before they
upload that 3meg .tif file through their 56K dial up connection <smile>.

<script language="JavaScript">
<!--
extensions = new Array(".JPG",".GIF",".PNG",".gif",".jpg",".png")
function allowedExt(fileType){
 var extension = fileType.substring(fileType.length-4, fileType.length)
 for (var i = 0; i < extensions.length; i++) {
   if (extension == extensions[i]) {
    return true
    break
  }
 }alert(errorMsg()); return false
}

function errorMsg(){
  alertTxt = "Please select one of the following file types: \n\r"
  for (var i = 3; i < extensions.length; i++){
   alertTxt += extensions[i] + " "
    {
  }
 }return alertTxt
}

//-->
</script>

Then use:

<form action="index.cfm" method="post" enctype="multipart/form-data"
name="uploadForm" OnSubmit="return allowedExt(photo.value);">
<input NAME="photo" TYPE="file" size="25>
<input type="submit" name="go" value="Upload Photo">
</form>



Best regards,

Dennis Powers
UXB Internet
(203)879-2844
http://www.uxbinfo.com/

-----Original Message-----
From: Dave Carabetta [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 06, 2002 3:13 PM
To: CF-Talk
Subject: Advanced CFCATCH Exception Types

I would like to trap a CFFILE error using CFTRY/CFCATCH if the user submits
a bad file type. I only want to allow them to upload .gif files.

I can use the CFCATCH TYPE="Any" to trap it, but I was hoping that I could
trap specifically for a bad file type.

I noticed that there are a whole slew of "advanced" exception types starting
with COM.* listed in the documentation, but I can't find one for a bad file
type.

Can one of those advanced types or a regular type be used other than "Any"?

Thanks,
Dave.


_________________________________________________________________
Join the world's largest e-mail service with MSN Hotmail.
http://www.hotmail.com

______________________________________________________________________
Why Share?
  Dedicated Win 2000 Server · PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER
  Instant Activation · $99/Month · Free Setup
  http://www.pennyhost.com/redirect.cfm?adcode=coldfusionc
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to