1

I have the following code:

Public Sub Save(path)
    Dim streamFile, fileItem, filePath, allowedExtensions
    allowedExtensions = ".jpg, .gif, .png, .zip, .7z, .exe, .bmp, .pdf, .doc, .docx"

    if Right(path, 1) <> "\" then path = path & "\" '"

    if not uploadedYet then Upload

    For Each fileItem In UploadedFiles.Items        
        Dim MyArray, extension

        MyArray = Split(fileItem, ".")
        extension = MyArray(UBound(MyArray)-1)

        '' # var extension = UCase(right(fileItem.FileName,5,);

        if(allowedExtensions.Contains(extension)) then  
            filePath = path & fileItem.FileName
            Set streamFile = Server.CreateObject("ADODB.Stream")
            streamFile.Type = adTypeBinary
            streamFile.Open
            StreamRequest.Position=fileItem.Start
            StreamRequest.CopyTo streamFile, fileItem.Length
            streamFile.SaveToFile filePath, adSaveCreateOverWrite
            streamFile.close
            Set streamFile = Nothing
            fileItem.Path = filePath
        end if
     Next
End Sub

I cannot seem to get this line correct:

MyArray = Split(fileItem, ".")

The browser is telling me:

Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method

/up/freeaspupload.asp, line 90

Everywhere I look up, it shows this is how you do it.

Anyone have any ideas what I am doing wrong or a way around this?

I just want to only allow certain extensions to be uploaded.

4

2 回答 2

4

在 VBScript 中,原始类型没有内置方法。所以,allowedExtensions不能有Contains方法。我认为这就是发生错误的原因。线条MyArray = Split(fileItem, ".")正确清晰。

if(allowedExtensions.Contains(extension)) 那么

您可以使用InStr在另一个词中搜索一个词。

'For case insensitive search
If InStr(1, BeingSearched, SearchedFor, vbTextCompare) Then
    'Contains
End If
于 2012-05-19T01:47:39.467 回答
2

好吧,Kul-Tigin 发现了您的代码的另一个问题,一旦您解决了这个问题实际上涉及的拆分问题,您就会崩溃。我怀疑您的 Split 函数失败的原因是它应该如下所示:

 MyArray = Split(fileItem.FileName, ".")

请注意,您可能应该传递对象FileName属性的值。fileItem似乎fileItem没有指定默认属性。

于 2012-05-21T12:18:26.053 回答