Solved

check file ext

Posted on 2006-11-17
4
246 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
Interesting problem when moving between environments 6 52
Htaccess - if subdomain "dev." 2 80
SCCM vs Windows server 5 83
Web server settings related to keepalive 1 126
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
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 …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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