?
Solved

Regarding arrays and SAfileUp

Posted on 2003-03-24
7
Medium Priority
?
234 Views
Last Modified: 2011-10-03
I am using SAfileUp with ASP to upload files to a folder. I want to prevent users from uploading files that end with web extensions (htm, html, asp, shtml, cfm, cfml) and/or force them to only upload MS Office and image files (doc, xls, ppt, gif, jpg, jpeg). I am able to get the extension of the uploaded file via this formula:

ext = Mid(upl.UserFilename, InstrRev(upl.UserFilename, ".") + 1)

And I have a table in the db that lists both acceptable (tblGood_Ext) and unacceptable extensions (tblBad_Ext). But I'm not that good at arrays to write a function for this. Please help.
0
Comment
Question by:teelions
[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
  • 4
  • 3
7 Comments
 
LVL 28

Expert Comment

by:sybe
ID: 8197235
so what do you want: allow only extension that you allow, or forbid only extensions that you forbid ??

<%

aValidExtensions = Array("doc","xls","ppt","gif",jpg","jpeg")

ext = Mid(upl.UserFilename, InstrRev(upl.UserFilename, ".") + 1)

If IsElementOfArray()ext,aValidExtensions) Then
    ' file has an "allowed" extension and can be saved
Else
    ' file has no "allowed" extension, don't dave it
End If


Function IsElementOfArray(var,arr)
    Dim element
    IsElementOfArray = False
    If Not IsArray(arr) Then Exit Function

    If IsArray(arr) Then
        For Each element In arr
            If var = element Then
                IsElementOfArray = True
                Exit For
            End If
        Next
    End If
End Function
%>
0
 
LVL 28

Expert Comment

by:sybe
ID: 8197242
typo, it should be:

If IsElementOfArray(ext,aValidExtensions) Then
0
 

Author Comment

by:teelions
ID: 8199238
I'll try #1 and let you know if it works for me. I think it's better to check for the "allowed" extensions because then it would place a limit on what can be uploaded. Thanks.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:teelions
ID: 8204396
I put this code in place:
  <%
'Grab document extension & check for acceptable file types
Dim aValidExtensions
Dim ext

aValidExtensions = Array("doc","xls","ppt","gif","jpg","jpeg","pdf","rtf","txt")

ext = Mid(upl.UserFilename, InstrRev(upl.UserFilename,".") + 1)

If IsElementOf(ext,aValidExtensions) Then
  Response.Write("The file type, " & ext & " is accepted.")
  Response.End
Else
  Response.Write("The file type, " & ext & " is <b>NOT</b> acceptable.")
  Response.End
End If
%>
But got this error:
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'IsElementOf'

0
 

Author Comment

by:teelions
ID: 8204432
Sorry - This is what I placed. Got the same error though:
<%
Function IsElementOfArray(var,arr)
   Dim element
   Dim aValidExtensions
   Dim ext
   
   IsElementOfArray = False
   If Not IsArray(arr) Then Exit Function

   If IsArray(arr) Then
       For Each element In arr
           If var = element Then
               IsElementOfArray = True
               Exit For
           End If
       Next
   End If
End Function

'Grab document extension & check for acceptable file types
Dim aValidExtensions
aValidExtensions = Array("doc","xls","ppt","gif","jpg","jpeg","pdf","rtf","txt")

ext = Mid(upl.UserFilename, InstrRev(upl.UserFilename,".") + 1)

If IsElementOf(ext,aValidExtensions) Then
  Response.Write("The file type, " & ext & " is accepted.")
  Response.End
Else
  Response.Write("The file type, " & ext & " is <b>NOT</b> acceptable.")
  Response.End
End If
%>
0
 
LVL 28

Accepted Solution

by:
sybe earned 500 total points
ID: 8204478
Replace this

If IsElementOf(ext,aValidExtensions) Then

with

If IsElementOfArray(ext,aValidExtensions) Then
0
 

Author Comment

by:teelions
ID: 8204792
It worked. Thanks!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

765 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