Salve ragazzi,
vi pongo un quesito sul quale sto impazzendo da giorni.
Ho bisogno di uno script asp con il quale prendo da un form quattro campi, un'immagine e tre di testo. Fin qui tutto bene.
Il problema si presenta quando clicco sul pulsante "Invia" ed il browser mi risponde con una bella pernacchia dicendomi "Chiamata di routine o argomento non validi".
Gli script che inserirò sotto non li ho fatti io, li ho scaricati da nonmiricordodove, da soli funzionano, è quando ho cercato di mettere tutto insieme che non vanno più...
Il bello è che su di un pc me lo da su di un file mentre su un altro me lo da su un altro file.
Vi scrivo i due errori (premesso che sono configurati in maniera identica, Winxp, IIs 5.1, Internet Explorer 7, Mozilla 3.0.10)
Sul pc fisso da:
Errore di run-time di Microsoft VBScript (0x800A0005)
Chiamata di routine o argomento non validi: 'MidB'
/belitri/public/clsUpload.asp, line 148
Mentre sul notebook
Errore di run-time di Microsoft VBScript (0x800A0005)
Chiamata di routine o argomento non validi:
/belitri/public/Inserisci.asp, line 40
Vi posto qui sotto i codici dei vari files con relativi nomi:
Caricamento.asp che sarebbe il form
<html>
<head>
<link href="../belitri.css" rel="stylesheet" type="text/css" /></head>
<body>
<H1>File Upload</H1>
<H2>To File System</H2>
<FORM method="post" encType="multipart/form-data" action="Inserisci.asp">
<table width="84%" border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#000000">
<tr>
<td width="50%"><strong>Immagine</strong></td>
<td width="50%"><input name="File1" type="File" size="50" /></td>
</tr>
<tr>
<td><strong>Titolo</strong></td>
<td><label>
<input name="Titolo" type="text" id="Titolo" size="50" maxlength="254" />
</label></td>
</tr>
<tr>
<td><strong>Testo</strong></td>
<td><label>
<textarea name="Storia" id="Storia" cols="50" rows="7"></textarea>
</label></td>
</tr>
<tr>
<td><strong>Note</strong></td>
<td><label>
<input name="Note" type="text" id="Note" size="50" />
</label></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" align="center"><input type="Submit" value="Upload" /></td>
</tr>
</table>
</FORM>
<p> </p>
</body>
</html>
Inserisci.asp La pagina che richiede dati al form (in neretto la riga che da errore)
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#INCLUDE FILE="clsUpload.asp"-->
<!--#INCLUDE FILE="Connessione.asp"-->
<%
Dim oUpload
Dim oFile
Dim sFileName
Dim oFSO
Dim sPath
Dim sNewData
Dim nLength
Dim bytBinaryData
'Dim sPath
Const nForReading = 1
Const nForWriting = 2
Const nForAppending = 8
' 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
' Save the file to the file system
sPath = Server.MapPath("Upload") & "\"
'sPath = "D:\Inetpub\webs\belitristoryit\public\Upload\"
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
oFSO.OpenTextFile(sPath & sFileName, nForWriting, True).Write sNewData Set oFSO = Nothing
Set oFile = Nothing
Set oUpload = Nothing
%>
<%' Database %>
<%
Dim dbUpload
Dim oField
'Dim oConn
Dim oRs
Dim sSQL
Dim dbFileName
Set dbUpload = New clsUpload
Set oFile = oUpload("File1")
' parse the file name
dbFileName = oFile.FileName
If Not InStr(sFileName, "\") = 0 Then
dbFileName = Mid(dbFileName, InStrRev(dbFileName, "\") + 1)
End If
Set oRs = Server.CreateObject("ADODB.Recordset")
sSQL = "SELECT FileID, FileName, FileSize, ContentType, BinaryData FROM Files WHERE 1=2"
oRs.Open sSQL, oConn, 3, 3
oRs.AddNew
oRs.Fields("FileName") = dbFileName
oRs.Fields("FileSize") = oFile.Length
oRs.Fields("ContentType") = oFile.ContentType
oRs.Fields("BinaryData").AppendChunk = oFile.BinaryData & ChrB(0)
oRs.Update
oRs.Close
sSQL = "SELECT Top 1 FileID, FileName From Files Order By FileID Desc"
oRs.Open sSQL, conn
'If Not oRs.EOF Then
%>
<!--File has been saved in database. View this file:<BR><BR>-->
<!--<A href="DataFile.asp?FileID=<%'=oRs(0)%>"><%'=oRs(1)%></A>-->
<%
'End If
Set oRs = Nothing
'Set conn = Nothing
Set oFile = Nothing
Set dbUpload = Nothing
%>
<%'Storie%>
<%
'Creo un recordset rsUtenti per poter inserire i dati nel database passati dal form
Set rsStorie = Server.CreateObject("ADODB.Recordset")
SQL = "SELECT * FROM Storie Order By ID Desc"
rsUtenti.Open SQL, conn, 3, 3
rsUtenti.Addnew
rsUtenti.Fields("Titolo") = Request.Form("Titolo")
rsUtenti.Fields("Storia") = Request.Form("Storia")
rsUtenti.Fields("Note") = Request.Form("Note")
'rsUtenti.Fields("Password") = Request.Form("Password")
rsUtenti.Update
%>
<%
'Chiudo il recordset e la connessione al database
rsStorie.Close
Set rsStorie = Nothing
conn.Close
Set conn = Nothing
%>
e
clsUpload.asp la pagina che fa l'upload (in neretto la riga che da errore)
<%
' ------------------------------------------------------------------------------
' 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
' Initialize Fields
nFieldCount = 0
ReDim oFields(-1)
' Read the bytes (binary data) into memory
lnByteCount = Request.TotalBytes
lnBytes = Request.BinaryRead(lnByteCount)
'Get the lnBoundaryBytes
lnStartPosition = 1
lnEndPosition = InstrB(lnStartPosition, lnBytes, CStrB(vbCr))
lnBoundaryBytes = MidB(lnBytes, lnStartPosition, lnEndPosition - lnStartPosition) lnBoundaryStart = InstrB(1, lnBytes, lnBoundaryBytes)
' Loop until the BoundaryBytes begin with "--"
Do Until (lnBoundaryStart = InstrB(lnBytes, lnBoundaryBytes & CStrB("--")))
' All data within this boundary is stored within a local dictionary
' to be appended to the class-scope dictionary.
ReDim Preserve oFields(nFieldCount)
nFieldCount = nFieldCount + 1
Set loField = New clsField
lnDispositionPosition = InstrB(lnBoundaryStart, lnBytes, CStrB("Content-Disposition"))
' Get an object name
lnStartPosition = InstrB(lnDispositionPosition, lnBytes, CStrB("name=")) + 6
lnEndPosition = InstrB(lnStartPosition, lnBytes, CStrB(""""))
lsFieldName = CStrU(MidB(lnBytes, lnStartPosition, lnEndPosition - lnStartPosition))
loField.FieldName = lsFieldName
' Get the location fo the file name.
lnFileNamePosition = InstrB(lnBoundaryStart, lnBytes, CStrB("filename="))
lnBoundaryEnd = InstrB(lnEndPosition, lnBytes, lnBoundaryBytes)
'Test if object is a file
If Not lnFileNamePosition = 0 And lnFileNamePosition < lnBoundaryEnd Then
' Parse Filename
lnStartPosition = lnFileNamePosition + 10
lnEndPosition = InstrB(lnStartPosition, lnBytes, CStrB(""""))
lsFileName = CStrU(MidB(lnBytes,lnStartPosition,lnEndPosition-lnStartPosition))
loField.FileName = lsFileName
' Parse Content-Type
lnStartPosition = InstrB(lnEndPosition,lnBytes,CStrB("Content-Type:")) + 14
lnEndPosition = InstrB(lnStartPosition,lnBytes,CStrB(vbCr))
ContentType = CStrU(MidB(lnBytes,lnStartPosition,lnEndPosition-lnStartPosition))
loField.ContentType = ContentType
' Parse Content
lnStartPosition = lnEndPosition + 4
lnEndPosition = InstrB(lnStartPosition,lnBytes,lnBoundaryBytes)-2
Value = MidB(lnBytes,lnStartPosition,lnEndPosition-lnStartPosition)
loField.BinaryData = Value & CStrB(vbNull)
loField.Length = LenB(Value)
Else
' 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
' ------------------------------------------------------------------------------
%>
Grazie per la pazienza