Ciao a tutti, sto provando ad adattare lo script trovato su html.it per uploadare file, ma non riesco ad adattarlo alle mie esigenze, io devo fare l'upload di due file assieme, ed ho modificato la form così:
codice:
<form action="upload.asp" method="post" enctype="multipart/form-data">
<table width="400" border="0" align="center">
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">Foto piccola, larghezza 90 pixel</font></td>
<td colspan="2"><input type="file" name="file1"></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">Foto grande, larghezza 250 pixel </font></td>
<td colspan="2"><input type="file" name="file2"></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif"></font></td>
<td></td>
<td></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif"></font></td>
<td></td>
<td></td>
</tr>
</table>
<input type="submit" value="Upload">
</p>
</form>
E lo script come da istruzioni così:
codice:
<%
'Questa variabile setta il percorso di dove effettuare l'upolad
'la cartella non puo non esistere lo script non la crea ! ! !
percorso = "/Immagini/"
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,"testo1") > 0 then
' testo1 = ContenutoFile
'end if
' Nel caso in cui fossero presenti piu campi basta duplicare
' la condizione cambiando unicamente il nome del campo
' es.
'if instr(Intestazione,"testo2") > 0 then
' testo2 = ContenutoFile
'end if
'if instr(Intestazione,"testo3") > 0 then
' testo3 = ContenutoFile
'end if
' Qui recupero il file da uploadare (se presente) e lo scrivo
' sul server
'response.write(instr(Intestazione,"file1"))
if instr(Intestazione,"file1") > 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,"file2") > 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,"file3") > 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
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
If Upload1 = true then
Response.Write "
La dimensione del file che hai uploadato è di " & DimensioneFile1*0.001 & "kb"
Response.Write "
Grazie di aver inviato il tuo file"
End If
If Upload2 = true then
Response.Write "
La dimensione del file che hai uploadato è di " & DimensioneFile2*0.001 & "kb"
Response.Write "
Grazie di aver inviato il tuo file"
End If
'If Upload3 = true then
' Response.Write "
La dimensione del file che hai uploadato è di " & DimensioneFile3*0.001 & "kb"
' Response.Write "
Grazie di aver inviato il tuo file"
'End If
End if
%>
Così facendo pero' mi fà l'upload solo del primo file, e non del secondo, perchè?
Ciao