Solved

check file ext

Posted on 2006-11-17
4
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
What You Need to Know when Searching for a Webhost Provider
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

687 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