Solved

check file ext

Posted on 2006-11-17
4
240 Views
Last Modified: 2013-12-24
hi i need to check my file ext before i upload, at the moment it does not work??


            <!---check its a image--->            
            <cfset allowfiles = "jpg,jpeg,gif,png">      
            <cfif listfindnocase(allowfiles,'form.image')>
            <cfset error = "Error: An articsdvfdst">
            </cfif>
0
Comment
Question by:pigmentarts
  • 2
4 Comments
 
LVL 25

Accepted Solution

by:
dgrafx earned 250 total points
ID: 17964816
can't do it that way
<script>
function fileType(field) {
var ok = true;
var Extensions = ".jpg,.gif";      
      
if(field!=null && field.value.length) {
      dots = field.value.split(".")
      thisType = "." + dots[dots.length-1]
      thisType = thisType.toLowerCase()            
      if(Extensions.toLowerCase().indexOf(thisType) == "-1") {
            ok = false;                        
      }
}      
      if(!ok) {
      alert("File Type is Not Allowed.\nUse "+Extensions+" Only.")
      return false
      }
      
}
</script>
<input type="file" name="imgfile" onblur="fileType(this)">

but if user doesn't have js enabled then you need to use CF
<cfif Not listfindnocase(Extensions,cffile.serverFileExt)>
File is not allowed :)
</cfif>
you'd do this after your cffile action="upload"
0
 
LVL 20

Assisted Solution

by:trailblazzyr55
trailblazzyr55 earned 250 total points
ID: 17965183
you could check using the ListFindNoCase() method however in your method you have to specify the delimeter as ".", default is a "," so this would be more correct...

<cfif not listFindNoCase(extList,cffile.serverFileExt,".")>
   Not Allowed
</cfif>

however, you can also filter/allow certain files to be uploaded in the cffile tag as well..., and therefore you wouldn't have to do this check above...
well you could to display a message to the user or something...

<cffile
  action = "upload"
  fileField = "form.field"
  destination = "you_absolute_path"
  nameConflict = "MakeUnique"
  accept = "image/jpg, image/jpg, image/jpeg, image/gif, image/png">
0
 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 17965202
please ignore the duplicate image/jpg in the accept attib... this is more correct

<cffile
  action = "upload"
  fileField = "form.field"
  destination = "you_absolute_path"
  nameConflict = "MakeUnique"
  accept = "image/jpg, image/jpeg, image/gif, image/png">
0
 
LVL 12

Author Comment

by:pigmentarts
ID: 17965517
thanks,

used both


doe the cf check first then just in case done,

 accept = "image/jpg, image/jpeg, image/gif, image/png">
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now