Hi Rick,

When the user submits their form, I would have a dropdown or hidden field
specify what type of file I am expecting (eg: an image).

At the end of the day, in my CMS my users are wanting to upload a particular
file type (eg: image) and I am wanting to validate that they have uploaded
what they have said they are uploading.

So, I would evaluate the mime type and file extension and compare them to
the allowed values for the specified file type they have said they are
uploading.

If they say they are uploading an image, but actually upload an exe file
renamed with a jpg extension, then the evaluation of the mime type will
catch them out.  If they are allowed to upload an exe, then they should
choose to upload an exe as their file type and my system will then expect an
exe extension and application mime type, and therefore allow the upload to
be completed.

Cheers,
Martyn

PS: I found the following link on Google that may help with evaluating the
mime type:

http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:48395

where filepath is the full physical path to a file you wish to determine 
the mimetype of...

#getPageContext().getServletContext().getMimeType(filePath)#

PPS: I would give you the correct code if I had actually written it already,
but I generally use mime type in regards to CFCONTENT and delivering a file
to a user that way.  I use PHP for uploading these days.

The code for that I am happy to share if you need it.  This code is readily
found on Google, the coder's best adviser :o)  Just search under "PHP File
Upload"




 

-----Original Message-----
From: Rick Faircloth [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, October 25, 2006 2:49 PM
To: CF-Talk
Subject: RE: Mime Type for File Upload

Not quite sure what's happening here on the user end...

Does the user have to specify an "Upload Type" for the CFSwitch Expression
variable?  Then the validation is run against their choice and the file they
are attempting to upload?



Rick

-----Original Message-----
From: Martyn Bowis [mailto:[EMAIL PROTECTED]
Sent: Tuesday, October 24, 2006 8:21 PM
To: CF-Talk
Subject: RE: Mime Type for File Upload

Hi Rick,

The following is a list of mime types:

http://www.netdesign.co.nz/mime.htm

I suggest that you use a cfswitch to validate your file uploads (see below).
You could also add another switch that evaluates mime type ... Which I
assume you are already doing, hence the need for the list.

Kind regards,
Martyn

<cfswitch expression="#UploadType#" >

        <cfcase value="Image" ><cfset lst_Extensions = "gif,jpg" ></cfcase>
        <cfcase value="Flash" ><cfset lst_Extensions = "swf" ></cfcase>
        <cfcase value="PDF" ><cfset lst_Extensions = "pdf" ></cfcase>
        <cfcase value="Movie" ><cfset lst_Extensions =
"mpg,mpeg,avi,mov,rm,ra,ram" ></cfcase>
        <cfcase value="Audio" ><cfset lst_Extensions = "mp3,wav" ></cfcase>
        <cfcase value="Zip" ><cfset lst_Extensions = "zip" ></cfcase>
        <cfcase value="File" ><cfset lst_Extensions = "csv,txt,xls,doc"
></cfcase>
        <cfcase value="MSWord" ><cfset lst_Extensions = "doc" ></cfcase>
        <cfcase value="MSExcel" ><cfset lst_Extensions = "csv,xls"
></cfcase>
        <cfcase value="MSPowerpoint" ><cfset lst_Extensions = "ppt"
></cfcase>
        <cfcase value="MSAccess" ><cfset lst_Extensions = "mdb" ></cfcase>
        <cfcase value="StyleSheet" ><cfset lst_Extensions = "css" ></cfcase>
        <cfcase value="FlashVideo" ><cfset lst_Extensions = "flv" ></cfcase>
        <cfdefaultcase><cfset lst_Extensions = "gif,jpg" ></cfdefaultcase>

</cfswitch>

<cfif ListFindNoCase(lst_Extensions,extension) >
        <cfset valid = true >
<cfelse>
        <cfset valid = false >
</cfif>

<cfif valid EQ true >
        <!--- process --->
<cfelse>
        <!--- error --->
</cfif>



 

-----Original Message-----
From: Rick Faircloth [mailto:[EMAIL PROTECTED]
Sent: Wednesday, October 25, 2006 12:50 PM
To: CF-Talk
Subject: Mime Type for File Upload

Need to specify the CFFILE "Accept" attributes for .doc and .pdf.

What would those be?

I know Accept  = "application/msword" would accept Word docs, but would they
be limited .doc filetype?

And what about .pdf. application or text or ???

I want to limit uploads to .doc and .pdf only.

Thanks,

Rick









~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:257949
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to