codice:
Dim percorso
percorso = "images/"
ByteRicevuti = Request.TotalBytes
if ByteRicevuti > 0 then
DatiRicevuti = Request.BinaryRead(ByteRicevuti)
FileBinario = RSBinaryToString(DatiRicevuti)
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,"data_ins") > 0 then
data_ins = ContenutoFile
end if
if instr(Intestazione,"nr_rivista") > 0 then
nr_rivista = ContenutoFile
end if
if instr(Intestazione,"sezione") > 0 then
sezione = ContenutoFile
end if
if instr(Intestazione,"titolo") > 0 then
titolo = ContenutoFile
titolo = replace(titolo, "'","''")
end if
if instr(Intestazione,"sottotit") > 0 then
sottotit = ContenutoFile
sottotit = replace(sottotit, "'","''")
end if
if instr(Intestazione,"testo") > 0 then
testo = ContenutoFile
testo = replace(testo, "'","''")
end if
if instr(Intestazione,"autore") > 0 then
autore = ContenutoFile
autore = replace(autore, "'", "''")
end if
if instr(Intestazione,"status") > 0 then
status = ContenutoFile
end if
' Qui recupero il file da uploadare (se presente) e lo scrivo
' sul server
'FILE 1
if instr(Intestazione,"miniatura") > 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 = il_nome_che_vuoi_tu
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
Il sistema è prelevato da freeasp.html.it, adattato alle mie esigenze (quindi con rinomno file, ecc...).
Lo stesso script funziona anche se hai più file da uploaddare, basta duplicare lo script, che estraei il file da uploaddare (ma in questo caso bisgna fare un include nella pagina con un file di funzioni).