Risultati da 1 a 7 di 7

Discussione: Problema in asp

  1. #1
    Il Puppies
    Data Registrazione
    01-12-03
    Messaggi
    331

    Predefinito Problema in asp

    Ciao ragazzi, avrei bisogno di un aiuto urgente. Mi scuso già da ora per la lunghezza del topic. Premetto che non sono un grande esperto di asp. Ho l'esigenza di inserire in un sito delle immagini. Dovrei quindi creare un codice che metta le immagini nel server e poi metta il link delle immagini sul database. Ho trovato questo codice, l'ho adattato ma mi restituisce un errore. Sapreste aiutarmi per favore? Vi posto le pagine con relativo codice.

    formimmagine.asp:

    Codice:
    <% 
    set cn=Server.CreateObject("ADODB.Connection")
    cn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/mdb-database/organigramma.mdb") & ";Jet OLEDB:Database Password=???????"
    %>
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Documento senza titolo</title>
    </head>
    <body>
    <% sql="Select * FROM giocatori order by id" 
       Set rs=cn.execute(sql)
    %>
    <% 
    do while not rs.EOF %>
    <table>
    <tr>
    <td><% = rs("nome") %> <% = rs("cognome") %>
    /td>
    <td>
    <form method="post" enctype="multipart/form-data" action="immaginearticoloinserita.asp" />
    <input type="hidden" name="name" value="<% = rs("id") %>" />
    <input type="file" name="file" size="20" />
    <input type="submit" value="OK" />
    </form>
    </td>
    </table>
    <% rs.movenext
    loop 
    %>
    </body>
    </html>
    <%
    cn.Close
    set cn= nothing
    %>
    loader.asp:

    Codice:
    <%
    
    
      Class Loader
        Private dict
        
        Private Sub Class_Initialize
          Set dict = Server.CreateObject("Scripting.Dictionary")
        End Sub
    
        Private Sub Class_Terminate
          If IsObject(intDict) Then
            intDict.RemoveAll
            Set intDict = Nothing
          End If
          If IsObject(dict) Then
            dict.RemoveAll
            Set dict = Nothing
          End If
        End Sub
    
        Public Property Get Count
          Count = dict.Count
        End Property
    
        Public Sub Initialize
          If Request.TotalBytes > 0 Then
            Dim binData
              binData = Request.BinaryRead(Request.TotalBytes)
              getData binData
          End If
        End Sub
    
        Public Function getFileData(name)
          If dict.Exists(name) Then
            getFileData = dict(name).Item("Value")
            Else
            getFileData = ""
          End If
        End Function
    
        Public Function getValue(name)
          Dim gv
          If dict.Exists(name) Then
            gv = CStr(dict(name).Item("Value"))
            
            gv = Left(gv,Len(gv)-2)
            getValue = gv
          Else
            getValue = ""
          End If
        End Function
    
        Public Function saveToFile(name, path)
          If dict.Exists(name) Then
            Dim temp
              temp = dict(name).Item("Value")
            Dim fso
              Set fso = Server.CreateObject("Scripting.FileSystemObject")
            Dim file
              Set file = fso.CreateTextFile(path)
                For tPoint = 1 to LenB(temp)
                    file.Write Chr(AscB(MidB(temp,tPoint,1)))
                Next
                file.Close
              saveToFile = True
          Else
              saveToFile = False
          End If
        End Function
    
        Public Function getFileName(name)
          If dict.Exists(name) Then
            Dim temp, tempPos
              temp = dict(name).Item("FileName")
              tempPos = 1 + InStrRev(temp, "\")
              getFileName = Mid(temp, tempPos)
          Else
            getFileName = ""
          End If
        End Function
    
        Public Function getFilePath(name)
          If dict.Exists(name) Then
            Dim temp, tempPos
              temp = dict(name).Item("FileName")
              tempPos = InStrRev(temp, "\")
              getFilePath = Mid(temp, 1, tempPos)
          Else
            getFilePath = ""
          End If
        End Function
    
        Public Function getFilePathComplete(name)
          If dict.Exists(name) Then
            getFilePathComplete = dict(name).Item("FileName")
          Else
            getFilePathComplete = ""
          End If
        End Function
    
        Public Function getFileSize(name)
          If dict.Exists(name) Then
            getFileSize = LenB(dict(name).Item("Value"))
          Else
            getFileSize = 0
          End If
        End Function
    
        Public Function getFileSizeTranslated(name)
          If dict.Exists(name) Then
            temp = LenB(dict(name).Item("Value"))
              If temp <= 1024 Then
                getFileSizeTranslated = temp & " bytes"  
              Else
                temp = FormatNumber((temp / 1024), 2)
                getFileSizeTranslated = temp & " kilobytes"
              End If
          Else
            getFileSizeTranslated = ""
          End If
        End Function
    
        Public Function getContentType(name)
          If dict.Exists(name) Then
            getContentType = dict(name).Item("ContentType")
          Else
            getContentType = ""
          End If
        End Function
    
      Private Sub getData(rawData)
        Dim separator 
          separator = MidB(rawData, 1, InstrB(1, rawData, ChrB(13)) - 1)
    
        Dim lenSeparator
          lenSeparator = LenB(separator)
    
        Dim currentPos
          currentPos = 1
        Dim inStrByte
          inStrByte = 1
        Dim value, mValue
        Dim tempValue
          tempValue = ""
    
        While inStrByte > 0
          inStrByte = InStrB(currentPos, rawData, separator)
          mValue = inStrByte - currentPos
    
          If mValue > 1 Then
            value = MidB(rawData, currentPos, mValue)
    
            Dim begPos, endPos, midValue, nValue
            Dim intDict
              Set intDict = Server.CreateObject("Scripting.Dictionary")
    
              begPos = 1 + InStrB(1, value, ChrB(34))
              endPos = InStrB(begPos + 1, value, ChrB(34))
              nValue = endPos
    
            Dim nameN
              nameN = MidB(value, begPos, endPos - begPos)
    
            Dim nameValue, isValid
              isValid = True
              
              If InStrB(1, value, stringToByte("Content-Type")) > 1 Then
    
                begPos = 1 + InStrB(endPos + 1, value, ChrB(34))
                endPos = InStrB(begPos + 1, value, ChrB(34))
    
                If endPos = 0 Then
                  endPos = begPos + 1
                  isValid = False
                End If
    
                midValue = MidB(value, begPos, endPos - begPos)
                  intDict.Add "FileName", trim(byteToString(midValue))
    
              begPos = 14 + InStrB(endPos + 1, value, stringToByte("Content-Type:"))
              endPos = InStrB(begPos, value, ChrB(13))
    
                midValue = MidB(value, begPos, endPos - begPos)
                  intDict.Add "ContentType", trim(byteToString(midValue))
    
                begPos = endPos + 4
                endPos = LenB(value)
    
                nameValue = MidB(value, begPos, ((endPos - begPos) - 1))
              Else
                nameValue = trim(byteToString(MidB(value, nValue + 5)))
              End If
    
              If isValid = True Then
    
                intDict.Add "Value", nameValue
                intDict.Add "Name", nameN
    
                dict.Add byteToString(nameN), intDict
              End If
          End If
    
          currentPos = lenSeparator + inStrByte
        Wend
      End Sub
      
      End Class
    
      Private Function stringToByte(toConv)
        Dim tempChar
         For i = 1 to Len(toConv)
           tempChar = Mid(toConv, i, 1)
          stringToByte = stringToByte & chrB(AscB(tempChar))
         Next
      End Function
    
      Private Function byteToString(toConv)
        For i = 1 to LenB(toConv)
          byteToString = byteToString & Chr(AscB(MidB(toConv,i,1))) 
        Next
      End Function
    %>
    ed infine immaginearticoloinserita.asp:

    Codice:
    <% 
    set cn=Server.CreateObject("ADODB.Connection")
    cn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/mdb-database/organigramma.mdb") & ";Jet OLEDB:Database Password=????????"
    %>
    
    <!--#include file="Loader.asp"-->
    <%
    
       ' load object
       Dim load
          Set load = new Loader
    
          ' calling initialize method
          load.initialize
    
       ' File binary data
       Dim fileData
          fileData = load.getFileData("file")
       ' File name
       Dim fileName
          fileName = LCase(load.getFileName("file"))
       ' File path
       Dim filePath
          filePath = load.getFilePath("file")
       ' File path complete
       Dim filePathComplete
          filePathComplete = load.getFilePathComplete("file")
       ' File size
       Dim fileSize
          fileSize = load.getFileSize("file")
       ' File size translated
       Dim fileSizeTranslated
          fileSizeTranslated = load.getFileSizeTranslated("file")
       ' Content Type
       Dim contentType
          contentType = load.getContentType("file")
       ' No. of Form elements
       Dim countElements
          countElements = load.Count
       ' Value of text input field "name"
       Dim nameInput
          nameInput = load.getValue("name")
       ' Path where file will be uploaded
       Dim pathToFile
          pathToFile = Server.mapPath("/public/immagini") & "\" & fileName
       ' Uploading file data
       Dim fileUploaded
          fileuploaded = load.saveToFile("file", pathToFile)
    	  Dim percorso
    	  percorso = "immagini" & FileName
       ' destroying load object
       Set load = Nothing
    %>
    <% sql= "UPDATE giocatori SET foto='"&percorso&"' Where id LIKE '"& nameInput &"'"
    Set rs=cn.Execute(sql)
    %>
    <%
    if fileUploaded = True Then
    Response.Write filename & "Aggiunto con successo"
    Else
    Response.Write "Nessun file è stato aggiunto, riprova!"
    End if
    %>
    <%
    cn.Close
    set cn= nothing
    %>
    quando inserisco una foto e spingo sull'ok mi carica la pagina immaginearticoloinserita.asp con l'errore:

    Script error detected at line 34.
    Source line: binData = Request.BinaryRead(Request.TotalBytes)
    Description: Tipo non corrispondente: 'Request.BinaryRead'


    potreste aiutarmi? Grazie tante e scusate ancora per la lunghezza della discussione.
    Ultima modifica di Tato; 20-03-08 alle 19:11:17

  2. #2
    Il Puppies
    Data Registrazione
    01-12-03
    Messaggi
    331

    Predefinito Re: Problema in asp

    Ragazzi, nessuno mi aiuta?

  3. #3
    Il Nonno L'avatar di Kralizek
    Data Registrazione
    14-10-01
    Località
    Stockholm
    Messaggi
    9,894

    Predefinito Re: Problema in asp

    non uso ASP da almeno 6 anni... :(

    (in genere il tag (code) aiuta a rendere leggibile il testo)

  4. #4
    Il Puppies
    Data Registrazione
    01-12-03
    Messaggi
    331

    Predefinito Re: Problema in asp

    Citazione Originariamente Scritto da Kralizek Visualizza Messaggio
    non uso ASP da almeno 6 anni... :(

    (in genere il tag (code) aiuta a rendere leggibile il testo)
    chiedo scusa. Cerco di aggiustarlo

  5. #5
    Il Nonno L'avatar di vaitrafra
    Data Registrazione
    23-09-01
    Località
    Scandiano
    Messaggi
    6,024

    Predefinito Re: Problema in asp

    Se cambi la riga incriminata e la sostituisci con queste
    Codice:
     Dim ByteCount, BinRead
    ByteCount = Request.TotalBytes
    BinRead = Request.BinaryRead(ByteCount)
    

    Vedrai che funzia.

  6. #6
    Il Puppies
    Data Registrazione
    01-12-03
    Messaggi
    331

    Predefinito Re: Problema in asp

    grazie per la risposta.
    Allora, ho provato a cambiare questa riga binData = Request.BinaryRead(Request.TotalBytes) con questa BinRead = Request.BinaryRead(ByteCount) e mi restituisce questo errore

    Script error detected at line 139.
    Source line: separator = MidB(rawData, 1, InstrB(1, rawData, ChrB(13)) - 1)
    Description: Chiamata di routine o argomento non validi: 'MidB'

  7. #7
    Il Puppies
    Data Registrazione
    01-12-03
    Messaggi
    331

    Predefinito Re: Problema in asp

    Citazione Originariamente Scritto da vaitrafra Visualizza Messaggio
    Se cambi la riga incriminata e la sostituisci con queste
    Codice:
     Dim ByteCount, BinRead
    ByteCount = Request.TotalBytes
    BinRead = Request.BinaryRead(ByteCount)
    

    Vedrai che funzia.
    ciao, ho provato a fare ciò che mi hai detto e mi viene scritto : "Nessun file è stato aggiunto, riprova!"
    Non riesco a capire se è un problema di sistemazione della cartella o di altro. Ripeto, non mi restituisce più nessun errore ma mi da quel messaggio.
    Potete aiutarmi per favore? Grazie tante.

Permessi di Scrittura

  • Tu non puoi inviare nuove discussioni
  • Tu non puoi inviare risposte
  • Tu non puoi inviare allegati
  • Tu non puoi modificare i tuoi messaggi
  • Il codice BB è Attivato
  • Le faccine sono Attivato
  • Il codice [IMG] è Attivato
  • Il codice HTML è Disattivato