Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Problema con download file

    Perchè non riesco a far funzionare questo script che forza il download?:
    codice:
     <%
    
    Response.Buffer = True
    Dim strFilePath, strFileSize, strFileName
    
    Const adTypeBinary = 1
    
    strFileName = Trim(Request.QueryString("file"))
    strFilePath = strFilename
    response.write strFilePath 
    
    Response.Clear
    
    Set objStream = Server.CreateObject("ADODB.Stream")
    objStream.Open
    objStream.Type = adTypeBinary
    objStream.LoadFromFile strFilePath
    
    strFileType = lcase(Right(strFileName, 4))
    
    Select Case strFileType
    Case ".asf"
    ContentType = "video/x-ms-asf"
    Case ".avi"
    ContentType = "video/avi"
    Case ".doc"
    ContentType = "application/msword"
    Case ".zip"
    ContentType = "application/zip"
    Case ".xls"
    ContentType = "application/vnd.ms-excel"
    Case ".gif"
    ContentType = "image/gif"
    Case ".jpg", "jpeg"
    ContentType = "image/jpeg"
    Case ".wav"
    ContentType = "audio/wav"
    Case ".mp3"
    ContentType = "audio/mpeg3"
    Case ".mpg", "mpeg"
    ContentType = "video/mpeg"
    Case ".rtf"
    ContentType = "application/rtf"
    Case ".htm", "html"
    ContentType = "text/html"
    Case ".asp"
    ContentType = "text/asp"
    
    Case Else
    ContentType = "application/octet-stream"
    End Select
    
    
    Response.AddHeader "Content-Disposition", "attachment; filename=" & strFileName
    Response.AddHeader "Content-Length", strFileSize
    Response.Charset = "UTF-8"
    Response.ContentType = ContentType
    
    Response.BinaryWrite objStream.Read
    Response.Flush
    
    objStream.Close
    Set objStream = Nothing
    
    %>
    Perchè fa così:


  2. #2
    Utente di HTML.it L'avatar di viki1967
    Registrato dal
    Feb 2003
    Messaggi
    1,757
    codice:
    <%
    
    Function BaseName(byVal Path)
    Dim Pos
    	Path = Replace(Path,"/","\")
    	Pos  = InStrRev(Path,"\")
    	If Pos>0 then 
    		BaseName = Mid(Path,Pos+1)
    	Else
    		BaseName = Path
    	End if
    end function
     
    Function ReadFile(FileName)
    Dim Stream , Path
    	On error resume next
    		Path = Server.MapPath(FileName)
    		If Err.Number<>0 then Path = FileName
    	On error goto 0
    	Set Stream = Server.CreateObject("ADODB.Stream")
    	Stream.Type=1
    	Stream.Open()
    	Stream.LoadFromFile Path
    	Stream.Position=0
    	ReadFile = Stream.Read()
    	Stream.Close()
    	Set Stream = Nothing
    End Function
     
    Server.ScriptTimeout=6000
    if Len(Trim(request.querystring("file"))) > 0 then
    	file = (request.querystring("file")) 
    else
    	Response.Write("file non specificato")
    	Response.end
    end if
     
    response.ContentType="application/octet-stream"
    response.AddHeader "Content-Disposition", "attachment; filename=" & BaseName(file)
    Response.BinaryWrite ReadFile(File)
    Response.End
    
    %>
    A S P : tutto il resto è noia...
    L I N U X : forse mi "converto"...

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 © 2026 vBulletin Solutions, Inc. All rights reserved.