Skip to main content
Inspiring
December 12, 2008
Question

Checking file extensions of uploaded files

  • December 12, 2008
  • 1 reply
  • 865 views
I am uploading an image using the code below, is there an easy way to tell if the server has received a JPG or a GIF?

<input type="file" name="image_1" size="90" style="background-color: #ededed; border-width: 1px; border-color: #ffcccc; color: black; font-size: 9pt;">

This topic has been closed for replies.

1 reply

Inspiring
December 12, 2008
I found this site that checks the extension file of the uploaded file.

http://www.bennadel.com/blog/834-Ask-Ben-Upload-And-Email-File-Using-ColdFusion.htm

Hope it helps
ACS LLCAuthor
Inspiring
December 12, 2008
Thanks for the reply,

I took a look but couldn't find anything relevant to the issue
Inspiring
December 12, 2008
> I took a look but couldn't find anything relevant to the issue

I only skimmed the entry. But it appears to use the uploaded file's extension to determine which file types are allowed. For example, this line tries to verify the file is a PDF, RTF or word document.

ie
<cfif NOT ListFindNoCase( "pdf,doc,rtf", CFFILE.ServerFileExt )>
....

You could use a similar check to determine if the uploaded file is a GIF or JPG (.jpg or .jpeg). Bear in mind file extensions can be changed. So extension alone does guarantee a file is of a particular type. It is more likely, but not a guarantee.