FARE L'UPLOAD DI UNA IMMAGINE IN UNA CARTELLA UTENTE. Ringrazio per l'aiuto datomi in special modo i Forums di ASPItalia.com, Aruba.it, Tuttobanner.net, ASPCode.
A) PAGINA DI ACCESSO uploadform.asp
<html><head><title>LOGIN</title></head><body>
<table width=360 bgcolor=#40576f cellspacing=1 align=center><tr>
<td width=400 align=center bgcolor=#40576f><FONT color=#ffffff size=2>
<b>ESEGUI IL LOGIN</b></td></tr>
<tr><td bgcolor="#B3D9FF"><BR><p align="center"><b><br>
<form method="POST" action="middle.asp?">
Nome: </font></b><input type="TEXT" name="Nome" size=30><br>
<input type="submit" name="Enter" value="Aggiungi">
</form></body></html>
B) PAGINA INTERMEDIA middle.asp Per stabilire la variabile session e validare l'utente (nel mio caso con SQL o Cookies)
<%
' ..... QUI valido l'utente ....
' .... SE valido:
Session("action")=Request.Form("Nome")
Response.redirect "upload.asp"
%>
C) PAGINA PER L'UPLOAD upload.asp 2 FORM per l'upload immagini e per variabili al DB, Email etc
<%
NewDir=session("action")
' IMPEDISCO CHE ENTRI DIRETTAMENTE E INSERISCA IMMAGINI
If NewDir ="" THEN
Response.redirect "uploadform.asp"
End IF
' CREO LA SUA DIRECTORY SE C'E' PROSEGUE CON on error resume next
Set FSO = Server.CreateObject ("Scripting.FileSystemObject")
on error resume next
' percorso
path = Server.MapPath(NewDir)
' crea la directory
FSO.CreateFolder(path)
' CONTROLLO - LI TOLGO AL MOMENTO DI PUBBLICARE
if err.Number<>0 then
Response.write "<P>Directory creata!"
else
Response.write "<P>Errore: " &_
err.description
end if
set FSO = Nothing
%>
<form method="POST" enctype="multipart/form-data" action="upload.asp?">
<BR>
<p align="center"><b><font size="2"<br>File: </font></b>
<input type="file" name="blob" size=30><br>
<input type="submit" name="Enter" value="Conferma">
</form>
<BR>
<form method="POST" action="upload.asp?action=go"><BR>
<p align="center"><b><Font size="2"><br>
Descrizione: </font></b><input type="TEXT" name="Descrizione" size=30><br>
<input type="submit" name="Enter" value="Aggiungi">
</form><BR>
<%
'STABILISCO LA SUA AREA DI UPLOAD
Dim folder
folder = "\uploads\" & NewDir' directory sul server con accesso in scrittura
' MIEI CONTROLLI DA TOGLIERE PRIMA DI PUBBLICARE
Response.Write NewDir
Response.write("<BR>")
response.write folder
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("Content-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("filename="))
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),RequestBin,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
contentType = UploadRequest.Item("blob").Item("ContentType")
filepathname = UploadRequest.Item("blob").Item("FileName")
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
value = UploadRequest.Item("blob").Item("Value")
'CREA COMPONENTE FileSytemObject
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
'CREA E SCRIVE IN UN File
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
' QUI
' INSERISCO COSA DEVE FARE SE SCEGLIE IL SECONDO FORM action=go
' CON SELECT CASE
%>
<html><head><title>UPLOAD FILE</title></head><body>
<table border=0 width=360 bgcolor=#000000 cellspacing=1 align=center><tr>
<td width=400 align=center bgcolor=#000000><FONT color=#FFFFFF size=2>
<b>OPERAZIONE RIUSCITA CON <%=filename%> !</b></FONT></td></tr>
<tr><td height="30" bgcolor="#B3D9FF" align=center>
<a href=uploadform.asp><font Size=2>CAMBIA UTENTE</a></td></TR>
<tr><td height="30" bgcolor="#B3D9FF" align=center>
<a href=logoff.asp>ESCI</font></a></td></tr>
</table></body></html>
D) LOGOFF - CANCELLO LA SESSION E REDIRIGO AL LOGIN
<%
Session("action") = ""
Response.Redirect "uploadform.asp"
%>
SAREBBERO GRADITE CORREZIONI/SUGGERIMENTI - Ciao
Marco