ecco il codice
codice:
'----------UPLOAD FILE TRASCRIZIONE----------
Dim path,receivedBytes,receivedData,binaryFile,signatureFile,segmentArray,start,contentFile,uploadName
Set FSO = CreateObject("Scripting.FileSystemObject")
'path = "c:\temp\FILESMANU\"
path = "c:\Inetpub\wwwroot\CTB_FILES\" & sCodice & "\"
'Controllo se esiste il percorso e la cartella
if fso.folderExists(path) then
'Tutto ok
else
'Devo creare la cartella con nome = sCodice
dim sNuovaDir
set sFile =CreateObject("Scripting.FileSystemObject")
'sNuovaDir = sFile.CreateFolder(Server.Mappath("/" & sCodice))
sNuovaDir = sFile.CreateFolder("c:\Inetpub\wwwroot\CTB_FILES\" & sCodice & "\")
set sFile=nothing
end if
'Response.Write ("PATH " & path & "
")
receivedBytes = Request.TotalBytes
If receivedBytes > 0 And Request.QueryString("empty") <> "s" Then
receivedData = Request.BinaryRead(receivedBytes)
For counter = 1 To LenB(receivedData)
binaryFile = binaryFile & Chr(AscB(MidB(receivedData, counter, 1)))
Next
signatureFile = Left(binaryFile,instr(binaryFile, "" & vbCrLf) - 1)
'Response.Write ("signatureFile " & signatureFile & "
")
segmentArray = Split(binaryFile, signatureFile)
'Response.Write ("segmentArray " & segmentArray & "
")
For item = 1 To UBound(segmentArray) - 1
start = InStr(segmentArray(item), "" & vbCrLf & "" & vbCrLf)
Intestazione = Left(segmentArray(item), start - 1)
start = start + Len("" & vbCrLf) + Len("" & vbCrLf)
contentFile = Mid(segmentArray(item), start, Len(segmentArray(item)) - start - 1)
' Qui recupero il file da uploadare (se presente) e lo scrivo sul server
If InStr(Intestazione, "nome_file") > 0 Then
i = instr(Intestazione, "filename=")
j = instr(i + 10, Intestazione, chr(34))
uploadName = Mid(Intestazione, i + 10, j - i - 10)
'Response.Write ("uploadName " & uploadName & "
")
i = InStrRev(uploadName, "\")
If i <> 0 Then
NomeFile = Mid(uploadName, i + 1)
Else
NomeFile = uploadName
End If
'Response.Write ("NomeFile " & NomeFile & "
")
If i <> 0 Then
Upload1 = True
DimensioneFile1 = Len(contentFile)
EstensioneFile1 = Right(contentFile, 3)
NomeFile1 = NomeFile
Set textStream = FSO.CreateTextFile(path & NomeFile1, True, False)
textStream.Write(contentFile)
textStream.Close()
Set textStream = Nothing
else
NomeFile1 = NomeFile
End if
'Response.Write ("NomeFile1 " & NomeFile1 & "
")
End if
Next
End If