Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 13
  1. #1
    Utente di HTML.it L'avatar di angelicab
    Registrato dal
    Sep 2001
    Messaggi
    1,515

    VBScript - upload di un file e valore di un altro campo del form

    ciao! sto usando questo script x effettuare l'upload di file ..
    codice:
    <%
     Server.ScriptTimeOut = 900
    Sub BuildUploadRequest(RequestBin)
      'Get the boundary
      PosBeg = 1
      PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
      if PosEnd = 0 then
        Response.Write "Form was submitted with no ENCTYPE=""multipart/form-data""
    "
        Response.Write "Please correct the form attributes and try again."
        Response.End
      end if
      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))
          FileName = Mid(FileName,InStrRev(FileName,"\")+1)
          '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 = FileName
          ValueBeg = PosBeg-1
          ValueLen = 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))
          ValueBeg = 0
          ValueEnd = 0
        End If
        'Add content to dictionary object
        UploadControl.Add "Value" , Value	
        UploadControl.Add "ValueBeg" , ValueBeg
        UploadControl.Add "ValueLen" , ValueLen	
        '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
    
    Function UploadFormRequest(name)
      on error resume next
      if UploadRequest.Item(name) then
        UploadFormRequest = UploadRequest.Item(name).Item("Value")
      end if  
    End Function
    
    'Process the upload
    UploadQueryString = Replace(Request.QueryString,"GP_upload=true","")
    if mid(UploadQueryString,1,1) = "&" then
    	UploadQueryString = Mid(UploadQueryString,2)
    end if
    
    GP_uploadAction = CStr(Request.ServerVariables("URL")) & "?GP_upload=true"
    If (Request.QueryString <> "") Then  
      if UploadQueryString <> "" then
    	  GP_uploadAction = GP_uploadAction & "&" & UploadQueryString
      end if 
    End If
    
    If (CStr(Request.QueryString("GP_upload")) <> "") Then
      
      GP_redirectPage = "insallega1.asp?testoal="&request("testo")&"&nome="
      If (GP_redirectPage = "") Then
        GP_redirectPage = CStr(Request.ServerVariables("URL"))
      end if
        
      RequestBin = Request.BinaryRead(Request.TotalBytes)
      Dim UploadRequest
      Set UploadRequest = CreateObject("Scripting.Dictionary")  
      BuildUploadRequest RequestBin
      
      GP_keys = UploadRequest.Keys
      for GP_i = 0 to UploadRequest.Count - 1
        GP_curKey = GP_keys(GP_i)
        'Save all uploaded files
        if UploadRequest.Item(GP_curKey).Item("FileName") <> "" then
    	  'nomifile = FileName
    	  nomifile = UploadRequest.Item(GP_curKey).Item("FileName")
          GP_value = UploadRequest.Item(GP_curKey).Item("Value")
          GP_valueBeg = UploadRequest.Item(GP_curKey).Item("ValueBeg")
          GP_valueLen = UploadRequest.Item(GP_curKey).Item("ValueLen")
    
          if GP_valueLen = 0 then
            Response.Write "An error has occured saving uploaded file!
    
    "
            Response.Write "Filename: " & Trim(GP_curPath) & UploadRequest.Item(GP_curKey).Item("FileName") & "
    "
            Response.Write "File does not exists or is empty.
    "
            Response.Write "Please correct and try again"
    	  	  response.End
    	    end if
    		
     if GP_i = 0 then		
    Nomef = Trim(GP_curPath) & UploadRequest.Item(GP_curKey).Item("FileName")
    else
    ciccio = Trim(GP_curPath) & UploadRequest.Item(GP_curKey).Item("FileName")
    end if 
         
          'Create a Stream instance
          Dim GP_strm1, GP_strm2
          Set GP_strm1 = Server.CreateObject("ADODB.Stream")
          Set GP_strm2 = Server.CreateObject("ADODB.Stream")
          
          'Open the stream
          GP_strm1.Open
          GP_strm1.Type = 1 'Binary
          GP_strm2.Open
          GP_strm2.Type = 1 'Binary
            
          GP_strm1.Write RequestBin
          GP_strm1.Position = GP_ValueBeg
          GP_strm1.CopyTo GP_strm2,GP_ValueLen
        
          'Create and Write to a File
         ' GP_curPath = Request.ServerVariables("PATH_INFO")
          'GP_curPath = Trim(Mid(GP_curPath,1,InStrRev(GP_curPath,"/")) & "../../../database/utenti/elezioni/")
    	  GP_curPath = ("../pagine/")
          if Mid(GP_curPath,Len(GP_curPath),1) <> "/" then
            GP_curPath = GP_curPath & "/"
          end if  
          on error resume next
          GP_strm2.SaveToFile Trim(Server.mappath(GP_curPath))& "\" & UploadRequest.Item(GP_curKey).Item("FileName"),2
          if err then
            Response.Write "An error has occured saving uploaded file!
    
    "
            Response.Write "Filename: " & Trim(GP_curPath) & UploadRequest.Item(GP_curKey).Item("FileName") & "
    "
            Response.Write "Maybe the destination directory does not exist, or you don't have write permission.
    "
            Response.Write "Please correct and try again"
      		  err.clear
    	  	  response.End
    	    end if
        end if
      next
      
      '***GP BEGIN REDIRECT:  with URL parameters (only if no Insert/Update)
      If (GP_redirectPage <> "") Then
        If (InStr(1, GP_redirectPage, "?", vbTextCompare) = 0 And UploadQueryString <> "") Then
          GP_redirectPage = GP_redirectPage & "?" & UploadQueryString
        End If
        Call Response.Redirect(GP_redirectPage+nomifile)  
      end if  
      '***GP END REDIRECT
    end if  
    if UploadQueryString <> "" then
      UploadQueryString = UploadQueryString & "&GP_upload=true"
    else  
      UploadQueryString = "GP_upload=true"
    end if  
    
    %>
    l'upload va bene .. solo che nel form da cui prelevo i dati x l'upload ho anche un campo testo... come faccio a recuperare il contenuto di questo campo??
    ........\ | /......
    ......(@ @)).....
    -oOO-(_)-OOo-
    ......Angie.....

  2. #2
    Utente di HTML.it L'avatar di willybit
    Registrato dal
    May 2001
    Messaggi
    4,367
    Ciao angelicab,

    per l'upload usi un form con method="post" e enctype="multipart/form-data"
    sinceramente un campo testo di un form così non saprei come prelevarlo in asp
    però potresti fare uno script js che all'onsubmit mette il valore del campo di testo in querystring all'action del form così lo puoi recuperare con un request.Querystring
    codice:
    <form method="post" enctype="multipart/form-data" action="TuoUpload.asp" onsubmit="this.action='TuoUpload.asp?NomeCampo='+this.NomeCampo.value">

  3. #3
    Utente di HTML.it L'avatar di angelicab
    Registrato dal
    Sep 2001
    Messaggi
    1,515
    come come?? basta quel codice che hai postato tu??

    e poi come recupero il valore?? come una normale querystring??
    ........\ | /......
    ......(@ @)).....
    -oOO-(_)-OOo-
    ......Angie.....

  4. #4
    Utente di HTML.it L'avatar di willybit
    Registrato dal
    May 2001
    Messaggi
    4,367
    Originariamente inviato da angelicab
    come come?? basta quel codice che hai postato tu??

    e poi come recupero il valore?? come una normale querystring??
    in teoria sì
    Request.QueryString("NomeCampo")

  5. #5
    Utente di HTML.it L'avatar di angelicab
    Registrato dal
    Sep 2001
    Messaggi
    1,515
    appena provo ti faccio sapere
    ........\ | /......
    ......(@ @)).....
    -oOO-(_)-OOo-
    ......Angie.....

  6. #6
    Utente di HTML.it L'avatar di willybit
    Registrato dal
    May 2001
    Messaggi
    4,367
    ooooochei! Famme sape'

  7. #7
    Utente di HTML.it L'avatar di angelicab
    Registrato dal
    Sep 2001
    Messaggi
    1,515
    non va
    ........\ | /......
    ......(@ @)).....
    -oOO-(_)-OOo-
    ......Angie.....

  8. #8
    Utente di HTML.it L'avatar di willybit
    Registrato dal
    May 2001
    Messaggi
    4,367
    azz

    puoi postare il codice del form?

  9. #9
    Utente di HTML.it L'avatar di angelicab
    Registrato dal
    Sep 2001
    Messaggi
    1,515
    codice:
    <form action="<%=GP_uploadAction%>" method="post" enctype="multipart/form-data" name="form" onsubmit="return misura();this.action=<%=GP_uploadAction%>">
    <input type="file" name="upfile" id=formImageSrc style="width: 150px" value='' size='2'>
    <input name="testo" type="text" id="testo" size="20" maxlength="50">
    <input type="submit" name="Submit" value="Invia">
    </form>
    ........\ | /......
    ......(@ @)).....
    -oOO-(_)-OOo-
    ......Angie.....

  10. #10
    Utente di HTML.it L'avatar di willybit
    Registrato dal
    May 2001
    Messaggi
    4,367
    hehehe mi posti anche la funzione misura()
    e la variabile GP_uploadAction cosa contiene?
    dai che piano piano ci arriviamo

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.