At skifte benzin- eller dieselbilen ud med en elbil er en fantastisk opgradering. Men for mange nye elbilejere kan det godt virke som en jungle at finde ud af, hvordan man oplader derhjemme.
Hvordan ser dit script ud? I mange scripts findes der en liste over de godkendte filtyper. Hvis der gør det kan du jo blot tilføje dem du ønsker. Eller evt lave en liste over dem du ikke ønsker hvis det er nemmere
Inc-fil: <% ' ------------------------------------------------------------------------------ ' Container of Field Properties Class clsField Public FileName Public ContentType Public Value Public FieldName Public Length Public BinaryData End Class ' ------------------------------------------------------------------------------ Class clsUpload ' ------------------------------------------------------------------------------ Private nFieldCount Private oFields()
' ------------------------------------------------------------------------------ Public Property Get Count() Count = nFieldCount End Property ' ------------------------------------------------------------------------------ Public Default Property Get Field(ByRef asFieldName) Dim lnLength Dim lnIndex
lnLength = UBound(oFields)
If IsNumeric(asFieldName) Then If lnLength >= asFieldName And asFieldName > -1 Then Set Field = oFields(asFieldName) Else Set Field = New clsField End If Else For lnIndex = 0 To lnLength If LCase(oFields(lnIndex).FieldName) = LCase(asFieldName) Then Set Field = oFields(lnIndex) Exit Property End If Next Set Field = New clsField End If End Property ' ------------------------------------------------------------------------------ Public Function Exists(ByRef avKeyIndex) Exists = Not IndexOf(avKeyIndex) = -1 End Function ' ------------------------------------------------------------------------------ Public Property Get ValueOf(ByRef avKeyIndex) Dim lnIndex lnIndex = IndexOf(avKeyIndex) if lnIndex = -1 Then Exit Property ValueOf = oFields(lnIndex).Value End Property ' ------------------------------------------------------------------------------ Public Property Get FileNameOf(ByRef avKeyIndex) Dim lnIndex lnIndex = IndexOf(avKeyIndex) if lnIndex = -1 Then Exit Property FileNameOf = oFields(lnIndex).FileName End Property ' ------------------------------------------------------------------------------ Public Property Get LengthOf(ByRef avKeyIndex) Dim lnIndex lnIndex = IndexOf(avKeyIndex) if lnIndex = -1 Then Exit Property LengthOf = oFields(lnIndex).LengthOf End Property ' ------------------------------------------------------------------------------ Public Property Get BinaryDataOf(ByRef avKeyIndex) Dim lnIndex lnIndex = IndexOf(avKeyIndex) if lnIndex = -1 Then Exit Property BinaryDataOf = oFields(lnIndex).BinaryData End Property ' ------------------------------------------------------------------------------ Private Function IndexOf(ByVal avKeyIndex) Dim lnIndex If IsNumeric(asFieldName) Then avKeyIndex = CLng(avKeyIndex) If nFieldCount > avKeyIndex And avKeyIndex > -1 Then IndexOf = avKeyIndex Else IndexOf = -1 End If Else For lnIndex = 0 To nFieldCount - 1 If LCase(oFields(lnIndex).FieldName) = LCase(avKeyIndex) Then IndexOf = lnIndex Exit Function End If Next IndexOf = -1 End If End Function ' ------------------------------------------------------------------------------ Public Property Get ContentTypeOf(ByRef avKeyIndex) Dim lnIndex lnIndex = IndexOf(avKeyIndex) if lnIndex = -1 Then Exit Property ContentTypeOf = oFields(lnIndex).ContentType End Property ' ------------------------------------------------------------------------------ Private Sub Class_Terminate() For lnIndex = 0 To nFieldCount - 1 Set oFields(0) = Nothing Next End Sub ' ------------------------------------------------------------------------------ Private Sub Class_Initialize()
Dim lnBytes ' Bytes received from the client Dim lnByteCount ' Number of bytes received Dim lnStartPosition ' Position at which content begins Dim lnEndPosition ' Position at which content ends
Dim loDic ' Contains properties of each ' specific field ' Local dictionary object(s) ' to be appended to class-scope ' dictioary object.
Dim lnBoundaryBytes ' Bytes contained within the current boundary Dim lnBoundaryStart ' Position at wich the current boundary begins ' within the lnBytes binary data. Dim lnBoundaryEnd ' Position at wich the current boundary ends ' within the lnBytes binary data. Dim lnDispositionPosition
Dim lsFieldName ' Name of the current field being parsed from ' Binary Data Dim lsFileName ' Name of the file within the current boundary Dim lnFileNamePosition ' Location of file name within current boundary
' Parse Content lnStartPosition = InstrB(lnDispositionPosition, lnBytes, CStrB(vbCr)) + 4 lnEndPosition = InstrB(lnStartPosition, lnBytes, lnBoundaryBytes) - 2 Value = CStrU(MidB(lnBytes,lnStartPosition,lnEndPosition-lnStartPosition)) loField.Value = Value loField.Length = Len(Value) End If
Set oFields(UBound(oFields)) = loField
'Loop to next object lnBoundaryStart = InstrB(lnBoundaryStart + LenB(lnBoundaryBytes), lnBytes, lnBoundaryBytes)
Set loField = Nothing
Loop
End Sub ' ------------------------------------------------------------------------------ Private Function CStrU(ByRef psByteString) Dim lnLength Dim lnPosition lnLength = LenB(psByteString) For lnPosition = 1 To lnLength CStrU = CStrU & Chr(AscB(MidB(psByteString, lnPosition, 1))) Next End Function ' ------------------------------------------------------------------------------ Private Function CStrB(ByRef psUnicodeString) Dim lnLength Dim lnPosition lnLength = Len(psUnicodeString) For lnPosition = 1 To lnLength CStrB = CStrB & ChrB(AscB(Mid(psUnicodeString, lnPosition, 1))) Next End Function ' ------------------------------------------------------------------------------ End Class ' ------------------------------------------------------------------------------ %>
' grab the uploaded file data Set oUpload = New clsUpload Set oFile = oUpload("File1")
' parse the file name sFileName = oFile.FileName If Not InStr(sFileName, "\") = 0 Then sFileName = Mid(sFileName, InStrRev(sFileName, "\") + 1) End If
' Convert the binary data to Ascii bytBinaryData = oFile.BinaryData nLength = LenB(bytBinaryData) For nIndex = 1 To nLength sNewData = sNewData & Chr(AscB(MidB(bytBinaryData, nIndex, 1))) Next
Set oFSO = Server.CreateObject("Scripting.FileSystemObject") oFSO.OpenTextFile(folder & sFileName, nForWriting, True).Write sNewData Set oFSO = Nothing
Response.write("Filen er uploaded!!!")
File_Name = oUpload("File_Name").Value 'Opretter billede i databasen Set rs_add_file = Server.CreateObject("ADODB.RecordSet") rs_add_file.open "Select * From [Files]" , Conn,1,3 rs_add_file.Addnew rs_add_file("Site_Id") = Site_Id rs_add_file("File_Name") = File_Name rs_add_file("File_Url") = sFileName rs_add_file.Update
Set oFile = Nothing Set oUpload = Nothing
response.Redirect("files.asp") %> <% ElseIf Request.QueryString("Action") = "delete" Then
'Sletter billede fra databasen og serveren Set rs_del_file = Server.CreateObject("ADODB.RecordSet") rs_del_file.open "Select * From [Files] Where Id =" & request.QueryString("File_Id") , Conn,1,3 Dim fso, MyFile Set fso = CreateObject("Scripting.FileSystemObject") fso.DeleteFile Server.MapPath("../userfiles/"&Unique_Name&"/files/"&rs_del_file("File_Url")&""), True rs_del_file.Delete rs_del_file.Update rs_del_file.Close response.redirect("files.asp") %> <% End If %>
det er heller ikke så meget at den skriver at typen ikke er godkendt, den kommer med nogle andre fejl, bla. script timeout.. Det som er mærkeligt er at den skriver det to gange: Active Server Pages error 'ASP 0113'
Script timed out
/admin/files.asp
The maximum amount of time for a script to execute was exceeded. You can change this limit by specifying a new value for the property Server.ScriptTimeout or by changing the value in the IIS administration tools.
Active Server Pages error 'ASP 0113'
Script timed out
/admin/files.asp
The maximum amount of time for a script to execute was exceeded. You can change this limit by specifying a new value for the property Server.ScriptTimeout or by changing the value in the IIS administration tools.
ja ok rettet - men der sker stadig intet.. jeg prøvede at uploade et pdf-dokument (521kb), og satte timeout til 2 min. der skete intet. Efter 2 minutter skrev den: Active Server Pages error 'ASP 0113'
Script timed out
/admin/files.asp
The maximum amount of time for a script to execute was exceeded. You can change this limit by specifying a new value for the property Server.ScriptTimeout or by changing the value in the IIS administration tools.
Jeg synes det er en voldsom kode...kan næsten ikke gennemskue den Har din udbyder ikke en komponent installeret som fx aspSmartUpload ? for så ville det vist være pænt lettere...i mine øjne Jeg kan i hvert fald nok ikke hjælpe dig mere med det du har desværre
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.