Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change CFFILE Error Page

Status
Not open for further replies.

rmz8

Programmer
Aug 24, 2000
210
US
I've setup a file upload form. The CFFILE tag restricts uploading to only certain MIME types. Everything works fine, but when someone tries to upload a file that is prohibited, an ugly ColdFusion error message comes up telling them of the the problem. I want to know if there is anyway that I can replace that message--and I can't use the CFERROR tag. Can I do some sort of verification using JavaScript?

Ryan ;-]
 
Hey Ryan,

I seem to recall that there was some html syntax that would tell the browser which files to show when it gives them a select box but I think only later versions of IE supported this. I don't know that you can customize the error page for the cfupload but this is what I would recommend.

1. Allow the upload of any file type.
2. Check the filename of the uploaded file and determine it's file type.
3. If it's acceptable, continue on.
4. If not, delete the file and display an appropriate error message.

The only hard part is determining the extension. An easy way to do this assuming the file name only has one &quot;.&quot; is with <cfset fileExtension = listgetat(cffile.serverfile,2,&quot;.&quot;)>. Since this would almost always be the case, it should be fine but I never like making assumptions ;)

GJ
 
Maybe a <cftry> <cfcatch> would do the trick..

<cftry>
<cffile action=&quot;UPLOAD&quot; filefield=&quot;filefield&quot; blah blah>
<cfcatch>An error has occurred.
Please hit back button and try again.
</cfcatch>
</cftry>

If an error occurs, the <cfcatch> would be displayed, otherwise....

Bobby
 
A more reliable way in my perception to capture the extension is the following:

<cfset extension=Reverse(Left(Reverse(file), (Find(&quot;.&quot;, Reverse(file)))))>

Voila (that's French for &quot;Works like a charm&quot;) ;-)

<webguru>iqof188</webguru>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top