Grazie Sghillo,
allora:
il codice è pari pari quello degli script scaricati, articolo di Simone Medas, letto da www.aspitalia.com/articoli/upload.aspx.
lo riporto di seguito; il bandolo della matassa è ritrovare il nome del file; se faccio una request.form mi da un errore (impossibile eseguirla).
Ci ho girato sopra fino alle 4 di stamani....
Ecco il codice per intero.
Grazie......
p.s. ho modificato il post, uno degli errori lo ho trovato ma non ci sono ancora!
<%
Dim bytecount
Dim retErr
bytecount = UpLoad()
if bytecount > 0 then
Dim id, title, description, filePath
title = ""
description = ""
if inputs("uploadFile").isFile = true then
' save the file
retErr = inputs("uploadFile").saveFileAs(Server.MapPath("images"), "")
end if
response.redirect "Riservatapr.asp"
else %>
<form name="MyForm" action="" method="post" encType="multipart/form-data">
<font face="Tahoma" size="3" color="#000080">Indica qui il file da usare
come immagine, o sfoglia le cartelle: fai la tua scelta e poi clicca su
'Invia file'</font>
<p>
<INPUT name="uploadFile" size="50" type="file"><INPUT type="submit" value="Invia file" name="SendData">
<br>
</p>
<input type="hidden" name="ffname" value="x">
</form>
<% end if %>
</BODY>
All'inizio dell'html c'è una include che 'tira dentro' lo script seguente: (è un pò lungo...)
<SCRIPT LANGUAGE=vbscript RUNAT=Server>
Dim inputs
' class to store data input
class clsInput
public name
public isFile
private pContent
public size
public fileName
public filePath
public property let content(newContent)
pContent = newContent
end property
public default property get content()
content = pContent
end property
' save the content into file with same filename as uploaded in current application path
public function saveFile()
saveFile = saveFileAs("", "")
end function
' save the content into file with given filename and path
public function saveFileAs(byVal destinationPath, byVal newFileName)
Dim withName
' if content is empty don't save it
if size = 0 then exit function
' append given path if any
if destinationPath <> "" then
withName = destinationPath
else
withName = Server.MapPath(".")
end if
' check if final slash exist, if don't, then do append it
if right(withName, 1) <> "\" then withName = withName & "\"
' append new filename if any
if newFileName <> "" then
withName = withName & newFileName
else
withName = withName & fileName
end if
on error resume next
Set fso = CreateObject("Scripting.FileSystemObject")
Set tf = fso.CreateTextFile(withName , True)
if Err.number = 0 then
tf.Write(pContent)
tf.Close
end if
if Err.number >0 then
saveFileAs = Err.Description
else
saveFileAs = ""
end if
end function
end class
Function UpLoad()
Dim bytArray
Dim bytecount
bytecount = Request.TotalBytes
if bytecount = 0 then
UpLoad = 0
exit function
end if
' continue only when bytecount>0
Set inputs = Server.CreateObject("Scripting.Dictionary")
bytArray = Request.BinaryRead(bytecount)
Dim objInput
Dim adLongVarChar
adLongVarChar = 201
Dim strByteToString
Dim lngLoop
Dim strIDInput
Dim lngStartPos
Dim lngFieldStartPos
Dim strInputHeader
Dim strContetType
Dim strInputName
Dim strFileName
Dim strFilePath
Dim strInputContent
Dim isFile
Dim rstTemp
' we using anrecordset object to quickly convert array of byte to string
Set rstTemp = Server.CreateObject("ADODB.Recordset")
rstTemp.Fields.Append "bytArray", adLongVarChar, lenb(bytArray)
rstTemp.Open
rstTemp.AddNew
rstTemp.Fields("bytArray").AppendChunk bytArray
rstTemp.Update
' we have getted the original string
strByteToString = rstTemp("bytArray")
Set rstTemp=Nothing
lngStartPos = 1
' get row separation
strIDInput = Mid(strByteToString, 1, InStr(1, strByteToString, vbCrLf) - 1)
' for each input field
While lngStartPos > 0
' resets all input variables
strInputHeader = ""
strContetType = ""
strInputContent = ""
strInputName = ""
strFileName = ""
strFilePath = ""
isFile = false
' skip row separation
lngStartPos = lngStartPos + Len(strIDInput) + 2
' gets current input header
strInputHeader = Mid(strByteToString, lngStartPos, InStr(lngStartPos, strByteToString, vbCrLf) + 2 - lngStartPos)
' skip input header
lngStartPos = lngStartPos + Len(strInputHeader)
' gets content type if any
strContetType = Mid(strByteToString, lngStartPos, InStr(lngStartPos, strByteToString, vbCrLf) + 2 - lngStartPos)
' skip content type
lngStartPos = lngStartPos + Len(strContetType)
If Len(strContetType) > 2 Then lngStartPos = lngStartPos + 2
' gets content input value
strInputContent = Mid(strByteToString, lngStartPos, InStr(lngStartPos, strByteToString, strIDInput) - 2 - lngStartPos)
' skip content type
lngStartPos = lngStartPos + Len(strInputContent) + 2
' gets input header fields
' gets "name" field
lngFieldStartPos = InStr(1, strInputHeader, "; name=", vbTextCompare) + 8
strInputName = Mid(strInputHeader, lngFieldStartPos, InStr(lngFieldStartPos, strInputHeader, Chr(34)) - lngFieldStartPos)
lngFieldStartPos = 0
' gets "filename" field if exists
lngFieldStartPos = InStr(1, strInputHeader, "; filename=", vbTextCompare)
If lngFieldStartPos > 0 Then
lngFieldStartPos = lngFieldStartPos + 12
strFilePath = Mid(strInputHeader, lngFieldStartPos, InStr(lngFieldStartPos, strInputHeader, Chr(34)) - lngFieldStartPos)
if len(strFilePath)>0 then
strFileName = Mid(strFilePath, InStrRev(strFilePath, "\", Len(strFilePath)) + 1)
strFilePath = Mid(strFilePath, 1, InStrRev(strFilePath, strFileName, Len(strFilePath)) - 1)
end if
End If
lngFieldStartPos = 0
'***********************************
' from this point we have all data
If strFileName <> "" Then
isFile = True
else
isFile = False
end if
' create the input object with current values
Set objInput = new clsInput
objInput.name = strInputName
objInput.isFile = isFile
objInput.content = strInputContent
objInput.size = len(strInputContent)
objInput.fileName = strFileName
objInput.filePath = strFilePath
' append just created input object to "inputs" collection
Set inputs(strInputName) = objInput
Set objInput = Nothing
'***********************************
' go to next input value
lngStartPos = InStr(lngStartPos, strByteToString, strIDInput)
' check if input separator is the last
If Mid(strByteToString, lngStartPos + Len(strIDInput) + 1, 1) = "-" Then lngStartPos = 0
Wend
bytArray = ""
UpLoad = bytecount
End Function
</SCRIPT>
Modificato da Cippo il 27 settembre 2004 11.56 -