Newsgroup: it.comp.www.asp
Titolo: Upload file tramite form

devo fare in modo che si collega abbia la possibilità tramite un form di
inviarmi un file
Grazie
http://www.miosito.it
Marco C

 inviarmi un file
Piccolo appunto: Se possibile leggere i post precedentemente inviati al
newsgroup !!!
In data 09/08/2000 io stesso ho inviato un messaggio dove rilasciavo appunto
questa informazione ... il newsgroup è molto utile per ricevere informazioni
e/o suggerimenti. Bisogna però utilizzarlo in modo corretto ... leggendo
anche i vecchi messaggi.
Comunque eccoti uno "spezzone" del mio vecchio messaggio:
A questo indirizzo: 
http://www.asptoday.com/articles/20000316.htm
 si può
trovare l'articolo che spiega come realizzare questa funzione ma, per chi
volesse provare sulla propria "pelle" senza leggere nulla dell'articolo
(anche se lo sconsiglio) ho "ripulito" i vari esempi e creato i file
necessari a tutte le operazioni (occhio ai nomi!!!)
---[immagini.asp]---
<%
' Verifica se ci sono opzioni da analizzare
Azione = Trim(Request.QueryString("action"))
Risultato = Trim(Request.QueryString("result"))
Immagine = Trim(Request.QueryString("image"))
Causa = Trim(Request.QueryString("cause"))
%>
<!-- Author Philippe Collignon -->
<!-- Email 
PhCol...@email.com
 -->
<HTML>
<HEAD>
<TITLE>Upload Form</TITLE>
</HEAD>
<BODY>
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=100% HEIGHT=100%><TR><TD
ALIGN=CENTER VALIGN=CENTER><TABLE CELLSPACING=0 CELLPADDING=0
BORDER=2><TR><TD>
<TABLE CELLSPACING=2 CELLPADDING=2 BORDER=0>
<FORM METHOD="Post" ENCTYPE="multipart/form-data" ACTION="outputFile.asp">
 <TR>
  <TD ALIGN=CENTER BGCOLOR="#FAC574"><B>Trasferimento file via
remoto</B></TD>
 </TR>
 <%If Azione = "" then%>
 <TR>
  <TD ALIGN=CENTER BGCOLOR="#FFFFB9"><INPUT TYPE="file" NAME="blob"></TD>
 </TR>
 <TR>
  <TD ALIGN=CENTER BGCOLOR="#FFFFB9"><INPUT TYPE="submit" NAME="Enter"
VALUE="Invia il file"></TD>
 </TR>
 <%Else%>
  <%If Risultato = "OK" then%>
  <TR>
   <TD ALIGN=CENTER BGCOLOR="#FFFFB9">Trasferimento file completato con
successo</TD>
  </TR>
  <%Else%>
  <TR>
   <TD ALIGN=LEFT BGCOLOR="#FFFFB9">Trasferimento file
fallito:<BR>L'estensione del file non è corretta.<BR>Trasferire solo file
con estensione .gif o .jpg</TD>
  </TR>
  <TR>
   <TD ALIGN=CENTER BGCOLOR="#FFFFB9"><INPUT TYPE="file" NAME="blob"></TD>
  </TR>
  <TR>
   <TD ALIGN=CENTER BGCOLOR="#FFFFB9"><INPUT TYPE="submit" NAME="Enter"
VALUE="Invia il file"></TD>
  </TR>
  <%End If%>
 <%End If%>
</FORM>
</TABLE>
</TD></TR></TABLE></TD></TR></TABLE>
</BODY>
</HTML>
---[fine immagini.asp]---
---[upload.asp]---
<%
' Author Philippe Collignon
' Email 
PhCol...@email.com
Sub BuildUploadRequest(RequestBin)
 'Get the boundary
 PosBeg = 1
 PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
 boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
 boundaryPos = InstrB(1,RequestBin,boundary)
 'Get all data inside the boundaries
 Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
  'Members variable of objects are put in a dictionary object
  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)
  'Test if object is of file type
  If  PosFile<>0 AND (PosFile<PosBound) Then
   'Get Filename, content-type and content of file
   PosBeg = PosFile + 10
   PosEnd =  InstrB(PosBeg,RequestBin,getByteString(chr(34)))
   FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
   'Add filename to dictionary object
   UploadControl.Add "FileName", FileName
   Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
   PosBeg = Pos+14
   PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
   'Add content-type to dictionary object
   ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
   UploadControl.Add "ContentType",ContentType
   'Get content of object
   PosBeg = PosEnd+4
   PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
   Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
   Else
   'Get content of object
   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
  'Add content to dictionary object
 UploadControl.Add "Value" , Value
  'Add dictionary object to main dictionary
 UploadRequest.Add name, UploadControl
  'Loop to next object
  BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
 Loop
End Sub
'String to byte string conversion
Function getByteString(StringStr)
 For i = 1 to Len(StringStr)
  char = Mid(StringStr,i,1)
 getByteString = getByteString & chrB(AscB(char))
 Next
End Function
'Byte string to string conversion
Function getString(StringBin)
 getString =""
 For intCount = 1 to LenB(StringBin)
 getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
 Next
End Function
%>
---[fine upload.asp]---
---[outputFile.asp]---
<%
' Author Philippe Collignon
' Email 
PhCol...@email.com
Response.Expires=0
Response.Buffer = TRUE
Response.Clear
'Response.BinaryWrite(Request.BinaryRead(Request.TotalBytes))
byteCount = Request.TotalBytes
'Response.BinaryWrite(Request.BinaryRead(varByteCount))
RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin
'email = UploadRequest.Item("email").Item("Value")
contentType = UploadRequest.Item("blob").Item("ContentType")
filepathname = UploadRequest.Item("blob").Item("FileName")
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
Estensione = Ucase(Right(FileName,3))
If Estensione = "GIF" or Estensione = "JPG" then
 value = UploadRequest.Item("blob").Item("Value")
 'Create FileSytemObject Component
 Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
 'Create and Write to a File
 pathEnd = Len(Server.mappath(Request.ServerVariables("PATH_INFO")))-14
 Set MyFile =
ScriptObject.CreateTextFile(Left(Server.mappath(Request.ServerVariables("PAT
H_INFO")),pathEnd) & filename)
 For i = 1 to LenB(value)
  MyFile.Write chr(AscB(MidB(value,i,1)))
 Next
 MyFile.Close
 Response.Redirect "immagini.asp?action=copy&result=OK&image=" & filename
Else
 Response.Redirect "immagini.asp?action=copy&result=failed&cause=extension"
End If
%>
<!--#include file="upload.asp"-->
---[fine upload.asp]---
Ciao
Michele Mariotti