Visualizzazione dei risultati da 1 a 9 su 9

Discussione: upload

  1. #1

    upload

    ho realizzato un upload verso server di un file con questo codice che riceve il nome del file da un form.
    Quando lo uso per file di piccole dimensioni funziona tutto...quando provo ad inviare file di qualche mega ottengo l'errore:
    Request object error 'ASP 0104 : 80004005'

    Operation not Allowed

    /stream/includes_DB/uploadfile.asp, line 72
    da cosa può dipendere?


    il mio codice è questo:


    Sub BuildUploadRequest(RequestBin)
    PosBeg = 1
    PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
    boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
    boundaryPos = InstrB(1,RequestBin,boundary)
    Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
    Dim UploadControl
    Set UploadControl = CreateObject("Scripting.Dictionary")
    'Get an object name
    Pos = InstrB(BoundaryPos,RequestBin,getByteString("Conte nt-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("filen ame="))
    PosBound = InstrB(PosEnd,RequestBin,boundary)
    If PosFile<>0 AND (PosFile<PosBound) Then
    PosBeg = PosFile + 10
    PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
    FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
    UploadControl.Add "FileName", FileName
    Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
    PosBeg = Pos+14
    PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
    ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
    UploadControl.Add "ContentType",ContentType
    PosBeg = PosEnd+4
    PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
    Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
    Else
    Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))
    PosBeg = Pos+4
    PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
    Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
    End If
    UploadControl.Add "Value" , Value
    UploadRequest.Add name, UploadControl
    BoundaryPos=InstrB(BoundaryPos+LenB(boundary),Requ estBin,boundary)
    Loop
    End Sub
    Function getByteString(StringStr)
    For i = 1 to Len(StringStr)
    char = Mid(StringStr,i,1)
    getByteString = getByteString & chrB(AscB(char))
    Next
    End Function
    Function getString(StringBin)
    getString =""
    For intCount = 1 to LenB(StringBin)
    getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
    Next
    End Function

    byteCount = Request.TotalBytes

    RequestBin = Request.BinaryRead(byteCount)
    Dim UploadRequest
    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,"\"))
    value = UploadRequest.Item("blob").Item("Value")
    'verifico l'estenzione del file inviato
    'IF left(filename,3)="wmv" then

    ' questo codice verifica l'esistenza di un file
    dim fso
    dim file

    set fso = Server.CreateObject("Scripting.FileSystemObject")
    file = (Server.mappath(folder)&"\"&filename)

    if fso.fileExists(file) then
    fso.DeleteFile(file)
    'response.write "Il file " & file & " cancellato!"

    else
    'response.write "Il file " & file & " non esiste!"
    end if
    set fso = nothing





    'Create FileSytemObject Component
    Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")

    'Create and Write to a File
    Set MyFile = ScriptObject.CreateTextFile(Server.mappath(folder) &"\"&filename)

    For i = 1 to LenB(value)
    MyFile.Write chr(AscB(MidB(value,i,1)))
    Next

    MyFile.Close
    response.write("OK")
    Ci sedemmo dalla parte del torto visto che tutti gli altri posti erano occupati."
    [Bertolt Brecht]

  2. #2

  3. #3
    grazie roby ma non ho ben capito lo script......

    dove devo indicare il path di destinazione?
    ho provato con il form di esempio dove ripota questo:




    <%
    If Request("Upload")="1" then
    Dim oUpload
    Set oUpload = new cUpload
    oUpload.AutoRename = False
    oUpload.Overwrite = true
    oUpload.SetPath "."
    oUpload.Upload
    'oUpload.SaveAs "Pippo.mp3"
    Set oUpload=Nothing
    end if
    %>
    <FORM METHOD="Post" enctype="multipart/form-data" ACTION="?upload=1">
    File : <INPUT TYPE="file" NAME="Campo1">

    <INPUT TYPE="submit" NAME="Enter">
    </FORM>
    sostituendo oUpload.setpath crea la cartella s non esiste ma non invia il file indicato nel form bensì
    pippo.mp3
    Ci sedemmo dalla parte del torto visto che tutti gli altri posti erano occupati."
    [Bertolt Brecht]

  4. #4
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    codice:
    oUpload.SetPath "/public/" ad esempio
    Roby

  5. #5
    ok questo si...

    ma con questo form riceve come file "pippo.mp3" e non quello che indico nel campo file del form
    Ci sedemmo dalla parte del torto visto che tutti gli altri posti erano occupati."
    [Bertolt Brecht]

  6. #6
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    Devi leggere i metodi della classe, mi pare fosse "filename"

    Roby

  7. #7
    si...devo analizzarle un pò...
    grazie
    e....forza roma x stasera
    Ci sedemmo dalla parte del torto visto che tutti gli altri posti erano occupati."
    [Bertolt Brecht]

  8. #8
    sarò sicuramente stupido io...ma non ne vengo a capo...

    sto utilizzando le classi indicate da roby ed effettivamente se indico nel form come
    oUpload.saveas FileName ottengo l'upload corretto nella cartella che indico in oUpload.setpath
    ne deduco che il nome del file è la variabile FileName(come appare abbastanza chiaro anche nelle classi)
    ma se voglio recuperare il nome del file per inserirlo in un db FileName non mi da niente....
    anche se provo a stampare la variabile
    response.write(FileName) non ottengo nulla.....del resto tale variabile risulta necessaria(e quindi non credo sia vuota)se la ometto non funziona lo script
    forse il formato di tale variabile non è stringa?Come devo fare per ottenere il nome file?
    ho provato con cstr(FileName) ma nulla cambia
    chi ha gia usato queste classi può aiutarmi?sono bloccato


    la porzione di codice è questa

    <%
    If Request("Upload")="1" then
    Dim oUpload
    Set oUpload = new cUpload
    oUpload.AutoRename = False
    oUpload.Overwrite = true
    oUpload.SetPath "/public/"
    oUpload.Upload
    [b]oUpload.SaveAs FileName[b]
    Set oUpload=Nothing
    end if
    %>
    <FORM METHOD="Post" enctype="multipart/form-data" ACTION="?upload=1">
    File : <INPUT TYPE="file" NAME="Campo1">

    <INPUT TYPE="submit" NAME="Enter">
    </FORM>
    Ci sedemmo dalla parte del torto visto che tutti gli altri posti erano occupati."
    [Bertolt Brecht]

  9. #9
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    codice:
    nomefile = oUpload.FileName
    Roby

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.