codice:
File di upload e scrittura - uoload.asp (inserisci_nuovo_session_reg)
<%
Dim folder
Dim data_inserimento
Dim categoria
Dim serie
Dim nome
Dim cognome
Dim pronome
Dim protettore_protettrice
......
Dim byteCount
Dim RequestBin
Dim PosBeg
Dim i
Dim char
Dim PosEnd
Dim boundary
Dim boundaryPos
Dim Pos
Dim intCount
Dim Name
Dim PosFile
Dim PosBound
Dim Value
Dim FileName
Dim ContentType
Dim nome_file
Dim Conn
Dim filepathname
Dim ScriptObject
Dim MyFile
Dim Sql
Dim Rs
folder = "/public/immagini"
Response.Expires=0
Response.Buffer = TRUE
Response.Clear
Sub BuildUploadRequest(RequestBin)
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
boundaryPos = InstrB(1,RequestBin,boundary)
Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
Dim UploadControl
Set UploadControl = CreateObject("Scripting.Dictionary")
'Get an object name
Pos = InstrB(BoundaryPos,RequestBin,getByteString("Conte nt-Disposition"))
Pos = InstrB(Pos,RequestBin,getByteString("name="))
PosBeg = Pos+6
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filen ame="))
PosBound = InstrB(PosEnd,RequestBin,boundary)
If PosFile<>0 AND (PosFile<PosBound) Then
PosBeg = PosFile + 10
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "FileName", FileName
Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
PosBeg = Pos+14
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "ContentType",ContentType
PosBeg = PosEnd+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
Else
Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))
PosBeg = Pos+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
End If
UploadControl.Add "Value" , Value
UploadRequest.Add name, UploadControl
BoundaryPos=InstrB(BoundaryPos+LenB(boundary),Requ estBin,boundary)
Loop
End Sub
Function getByteString(StringStr)
For i = 1 to Len(StringStr)
char = Mid(StringStr,i,1)
getByteString = getByteString & chrB(AscB(char))
Next
End Function
Function getString(StringBin)
getString =""
For intCount = 1 to LenB(StringBin)
getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
Next
End Function
byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin
'progressivo = UploadRequest.Item("progressivo").Item("Value")
'data_inserimento = UploadRequest.Item("data_inserimento").Item("Value ")
categoria = UploadRequest.Item("categoria").Item("Value")
serie = UploadRequest.Item("serie").Item("Value")
nome = UploadRequest.Item("nome").Item("Value")
cognome = UploadRequest.Item("cognome").Item("Value")
pronome = UploadRequest.Item("pronome").Item("Value")
........
'If IsNull(categoria) OR categoria = "" OR IsNull(serie) OR serie = "" Then
'Response.Write ("<center><br><b>CAMPI OBBLIGATORI!</b><br><br><a href='javascript:history.back()'><b>RITORNA</b></a></center>")
'Response.End
'End if
'etas=Datediff("yyyy",data_inserimento)
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Driver={MySQL ODBC 3.51 Driver};SERVER=;Database=Sql1_1;port=;UID=Sql;PWD= ;"
if UploadRequest.Item("foto1").Item("FileName")="" then
--> ho provato a modificare questa sezione, inserendo anche gli altri Item ma nulla :(
Else
contentType = UploadRequest.Item("foto1").Item("ContentType")
filepathname = UploadRequest.Item("foto1").Item("FileName")
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
value = UploadRequest.Item("foto1").Item("Value")
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
Set MyFile = ScriptObject.CreateTextFile(Server.mappath(folder) &"\"&filename)
For i = 1 to LenB(value)
MyFile.Write chr(AscB(MidB(value,i,1)))
Next
MyFile.Close
End if
Sql = "Select * FROM santini"
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.Open SQL, Conn, 1, 2
Rs.AddNew
Rs("data_inserimento") = data_inserimento
Rs("categoria") = categoria
Rs("serie") = serie
Rs("nome") = nome
Rs("cognome") = cognome
Rs("pronome") = pronome
Rs("protettore_protettrice") = protettore_protettrice
....
Rs("foto1") = filename1
Rs("foto2") = filename2
Rs("foto3") = filename3
Rs("foto4") = filename4
'Rs("data_inserimento") = date()
Rs.UpDate
Rs.Close
Set Rs = Nothing
Conn.Close
Set Conn = Nothing
Response.Redirect("registrazione_effettuata.asp#ok ")
%>
Sorry spero che ora sia leggibile.