codice:
<%
'Questa variabile setta il percorso di dove effettuare l'upolad
'la cartella non puo non esistere lo script non la crea ! ! !
percorso = "/public/mail/"
Server.ScriptTimeout = 1500
ByteRicevuti = Request.TotalBytes
if ByteRicevuti > 0 then
DatiRicevuti = Request.BinaryRead(ByteRicevuti)
For i = 1 To lenB(DatiRicevuti)
FileBinario = FileBinario & chr(ascB(midB(DatiRicevuti,i,1)))
Next
FirmaFile = left(FileBinario,instr(FileBinario,"" & vbCrLf)-1)
ArrPezzi = split(FileBinario,FirmaFile)
for item = 1 to ubound(ArrPezzi)-1
Inizio = instr(ArrPezzi(item),"" & vbCrLf & "" & vbCrLf)
Intestazione = left(ArrPezzi(item),Inizio-1)
Inizio = Inizio + len("" & vbCrLf) + len("" & vbCrLf)
ContenutoFile = mid(ArrPezzi(item),Inizio,len(ArrPezzi(item))-Inizio-1)
' Recupero i campi se sono compilati
if instr(Intestazione,"mail") > 0 then
mail = ContenutoFile
response.write mail
end if
' Nel caso in cui fossero presenti piu campi basta duplicare
' la condizione cambiando unicamente il nome del campo
' es.
if instr(Intestazione,"data") > 0 then
data = ContenutoFile
end if
if instr(Intestazione,"mittente") > 0 then
mittente = ContenutoFile
end if
if instr(Intestazione,"destinatario") > 0 then
destinatario = ContenutoFile
end if
if instr(Intestazione,"oggetto") > 0 then
oggetto = ContenutoFile
end if
if instr(Intestazione,"allegato1") > 0 then
allegato1 = ContenutoFile
end if
if instr(Intestazione,"allegato2") > 0 then
allegato2 = ContenutoFile
end if
if instr(Intestazione,"allegato3") > 0 then
allegato3 = ContenutoFile
end if
if instr(Intestazione,"allegato4") > 0 then
allegato4 = ContenutoFile
end if
if instr(Intestazione,"allegato5") > 0 then
allegato5 = ContenutoFile
end if
' Qui recupero il file da uploadare (se presente) e lo scrivo
' sul server
if instr(Intestazione,"mail") > 0 then
i = instr(Intestazione,"filename=")
j = instr(i + 10,Intestazione,chr(34))
NomeUpload = mid(Intestazione,i + 10,j-i-10)
i = instrRev(NomeUpload,"\")
if i<>0 then
NomeFile = mid(NomeUpload,i + 1)
else
NomeFile = NomeUpload
end if
if i<>0 then
Set FSO = CreateObject("Scripting.FileSystemObject")
Upload1 = True
DimensioneFile1 = len(ContenutoFile)
EstensioneFile1 = right(ContenutoFile,3)
NomeFile1 = NomeFile
Set textStream = FSO.CreateTextFile(server.mappath(percorso & NomeFile1), True, False)
textStream.Write ContenutoFile
textStream.Close
Set textStream = Nothing
Set FSO = Nothing
end if
end if
' Lo stesso discorso vale anche per i campi dei file :
' Nel caso in cui fossero presenti piu file basta duplicare
' la condizione cambiando unicamente il nome del campo
' es.
if instr(Intestazione,"allegato1") > 0 then
i = instr(Intestazione,"filename = ")
j = instr(i + 10,Intestazione,chr(34))
NomeUpload = mid(Intestazione,i + 10,j-i-10)
i = instrRev(NomeUpload,"\")
if i<>0 then
NomeFile = mid(NomeUpload,i + 1)
else
NomeFile = NomeUpload
end if
if i<>0 then
Set FSO = CreateObject("Scripting.FileSystemObject")
Upload2 = True
DimensioneFile2 = len(ContenutoFile)
EstensioneFile2 = right(ContenutoFile,3)
NomeFile2 = NomeFile
Set textStream = FSO.CreateTextFile(server.mappath(percorso & NomeFile2), True, False)
textStream.Write ContenutoFile
textStream.Close
Set textStream = Nothing
Set FSO = Nothing
end if
end if
if instr(Intestazione,"allegato2") > 0 then
i = instr(Intestazione,"filename = ")
j = instr(i + 10,Intestazione,chr(34))
NomeUpload = mid(Intestazione,i + 10,j-i-10)
i = instrRev(NomeUpload,"\")
if i<>0 then
NomeFile = mid(NomeUpload,i + 1)
else
NomeFile = NomeUpload
end if
if i<>0 then
Set FSO = CreateObject("Scripting.FileSystemObject")
Upload3 = True
DimensioneFile3 = len(ContenutoFile)
EstensioneFile3 = right(ContenutoFile,3)
NomeFile3 = NomeFile
Set textStream = FSO.CreateTextFile(server.mappath(percorso & NomeFile3), True, False)
textStream.Write ContenutoFile
textStream.Close
Set textStream = Nothing
Set FSO = Nothing
end if
end if
if instr(Intestazione,"allegato3") > 0 then
i = instr(Intestazione,"filename = ")
j = instr(i + 10,Intestazione,chr(34))
NomeUpload = mid(Intestazione,i + 10,j-i-10)
i = instrRev(NomeUpload,"\")
if i<>0 then
NomeFile = mid(NomeUpload,i + 1)
else
NomeFile = NomeUpload
end if
if i<>0 then
Set FSO = CreateObject("Scripting.FileSystemObject")
Upload4 = True
DimensioneFile4 = len(ContenutoFile)
EstensioneFile4 = right(ContenutoFile,3)
NomeFile4 = NomeFile
Set textStream = FSO.CreateTextFile(server.mappath(percorso & NomeFile4), True, False)
textStream.Write ContenutoFile
textStream.Close
Set textStream = Nothing
Set FSO = Nothing
end if
end if
if instr(Intestazione,"allegato4") > 0 then
i = instr(Intestazione,"filename = ")
j = instr(i + 10,Intestazione,chr(34))
NomeUpload = mid(Intestazione,i + 10,j-i-10)
i = instrRev(NomeUpload,"\")
if i<>0 then
NomeFile = mid(NomeUpload,i + 1)
else
NomeFile = NomeUpload
end if
if i<>0 then
Set FSO = CreateObject("Scripting.FileSystemObject")
Upload5 = True
DimensioneFile5 = len(ContenutoFile)
EstensioneFile5 = right(ContenutoFile,3)
NomeFile5 = NomeFile
Set textStream = FSO.CreateTextFile(server.mappath(percorso & NomeFile5), True, False)
textStream.Write ContenutoFile
textStream.Close
Set textStream = Nothing
Set FSO = Nothing
end if
end if
if instr(Intestazione,"allegato5") > 0 then
i = instr(Intestazione,"filename = ")
j = instr(i + 10,Intestazione,chr(34))
NomeUpload = mid(Intestazione,i + 10,j-i-10)
i = instrRev(NomeUpload,"\")
if i<>0 then
NomeFile = mid(NomeUpload,i + 1)
else
NomeFile = NomeUpload
end if
if i<>0 then
Set FSO = CreateObject("Scripting.FileSystemObject")
Upload6 = True
DimensioneFile6 = len(ContenutoFile)
EstensioneFile6 = right(ContenutoFile,3)
NomeFile6 = NomeFile
Set textStream = FSO.CreateTextFile(server.mappath(percorso & NomeFile6), True, False)
textStream.Write ContenutoFile
textStream.Close
Set textStream = Nothing
Set FSO = Nothing
end if
end if
next
' Da qui in poi è possibile fare esegiure allo script altre operazioni
' inserire qui gli script aggiuntivi che si vogliono eseguire dopo l'upload
' Per esempio visualizzare quello che è stato inserito all'interno del
' compo testo
'Response.Write "Il valore immesso nella testo1 è " & testo1 & "
"
' Utilizzando il sistema descritto sopra è possibile visualizzare campi
' testo aggiuntivi presenti nel form
' Response.Write "Il valore immesso nella testo2 è " & testo2 & "
"
' Response.Write "Il valore immesso nella testo3 è " & testo3 & "
"
' E la stessa cosa per i campi dove è stato eseguito l'upload dei file
End if
ConnectionString = "Provider=sqloledb; Data Source=XXXXXX; Initial Catalog=XXXXXX; User Id=XXXXXX; Password=xxxxxxxx;"
Set Connection = Server.CreateObject("ADODB.Connection")
Connection.Open ConnectionString
conta = "SELECT * FROM mail_book"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open conta, Connection ,3,3
rs.addnew
rs(1) = data
rs(2) = mittente
rs(3) = destinatario
rs(4) = oggetto
rs(5) = nomefile1
rs(6) = nomefile2
rs(7) = nomefile3
rs(8) = nomefile4
rs(9) = nomefile5
rs(10) = nomefile6
rs.update
%>