Solved

check file ext

Posted on 2006-11-17
4
245 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Firewall Speed Issue 6 68
.htaccess rewrite url with querystring problem 13 96
AWS New EC2 Instance and EBS Storage 2 79
Two wordpress questions 3 46
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 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