<!--#include file="upload.asp"-->
<%
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("/mdb-database/GestioneJBProf.mdb")

'percorsoassolutosito="e:/Siti Web/jbprof.com/"            	'LOCALE
'percorsoassolutosito="d:\inetpub\webs\jbprofcom\"			'ARUBA
percorsoassolutosito="c:\inetpub\wwwroot\www.jbprof.com\"			'ARUBA
Dim UploadRequest
if Request.QueryString("Tipo")="IMG_DOC" then
Response.Expires=0
  Response.Buffer = TRUE
  Response.Clear
  byteCount = Request.TotalBytes
  RequestBin = Request.BinaryRead(byteCount)
  
  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,"\"))
  		punto = InStrRev(filename, ".")
  		estensione = Right(filename, Len(filename) - punto)
  		'INSERIRE GESTIONE DELLE ESTENSIONI
 		 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("PATH_INFO")),pathEnd) & filename)
 
  		For i = 1 to LenB(value)
	 		MyFile.Write chr(AscB(MidB(value,i,1)))
  		Next
  		MyFile.Close

nomefile=Request.QueryString("IDUT") & "." & estensione
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.GetFile(percorsoassolutosito & "/public/" &  filename)
f.Copy(percorsoassolutosito & "/public/docenti/" &  nomefile)
set f=nothing
set fs=nothing


Set FileObject=CreateObject("Scripting.FileSystemObject")
FileObject.DeleteFile percorsoassolutosito & "/public/" & filename
Set FileObject=Nothing

idutente=CINT(Request.QueryString("IDUT"))

	strSQLaggiorna = "SELECT * FROM Docenti WHERE IDDocente=" & CINT(Request.QueryString("IDUT"))
	Set objRS = Server.CreateObject("ADODB.Recordset")
	objRS.Open strSQLaggiorna, objConn, 3, 3
		objRS("Image_Docenti")=nomefile
	objRS.Update
	objRS.Close
	Set objRS = Nothing
	Response.Redirect "../-site-/area_riservata_admin_docenti2.asp?IDUT=" & Request.QueryString("IDUT")

		'Response.Redirect "../-site-/areasoci.asp?menu=CONNASS2&stato=ok"
end if

if Request.QueryString("Tipo")="CUR_DOC" then
Response.Expires=0
  Response.Buffer = TRUE
  Response.Clear
  byteCount = Request.TotalBytes
  RequestBin = Request.BinaryRead(byteCount)

  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,"\"))
  		punto = InStrRev(filename, ".")
  		estensione = Right(filename, Len(filename) - punto)
  		'INSERIRE GESTIONE DELLE ESTENSIONI
 		 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("PATH_INFO")),pathEnd) & filename)
 
  		For i = 1 to LenB(value)
	 		MyFile.Write chr(AscB(MidB(value,i,1)))
  		Next
  		MyFile.Close

nomefile=Request.QueryString("IDUT") & "." & estensione
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.GetFile(percorsoassolutosito & "/public/" &  filename)
f.Copy(percorsoassolutosito & "/public/docenti/Curriculum/" &  nomefile)
set f=nothing
set fs=nothing


Set FileObject=CreateObject("Scripting.FileSystemObject")
FileObject.DeleteFile percorsoassolutosito & "/public/" & filename
Set FileObject=Nothing

idutente=CINT(Request.QueryString("IDUT"))

	strSQLaggiorna = "SELECT * FROM Docenti WHERE IDDocente=" & CINT(Request.QueryString("IDUT"))
	Set objRS = Server.CreateObject("ADODB.Recordset")
	objRS.Open strSQLaggiorna, objConn, 3, 3
		objRS("Curriculum_Docente")=nomefile
	objRS.Update
	objRS.Close
	Set objRS = Nothing
	Response.Redirect "../-site-/area_riservata_admin_docenti2.asp?IDUT=" & Request.QueryString("IDUT")

		'Response.Redirect "../-site-/areasoci.asp?menu=CONNASS2&stato=ok"
end if


objConn.Close
Set objConn = Nothing
%>
