Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11

Discussione: Visualizzare file

  1. #1

    Visualizzare file

    Salve gente !

    Ho uno script che legge dei file di diverse estensioni e li visualizza nel browser utilizzando un visualizzatore opportuno ( acrobat reader , ecxel , word ) . . .

    Leggo i file trammite STREAM solamente che ho dei problemi con alcune estensioni.

    Quali sono gli header minimi necessari e corretti da settare per avere il file visualizzato con il browser opportuno ???

    I PDF , GIF , BMP vengono visualizzati correttamente , mentre DOC , XLS e TIF prima di venir visualizzati appare la finestra in cui si chiede se si desidera aprirli oppure salvarli . . .

    HELP

  2. #2
    i content type sono settati bene ??

    e poi posta il codice ...

  3. #3
    codice:
    <%@ Language=VBScript %>
    <%
    Response.Expires = 0
    Response.ExpiresAbsolute = Now() - 1
    Response.AddHeader "pragma","no-cache"
    Response.AddHeader "cache-control","private"
    Response.CacheControl = "no-cache" 
    Response.Buffer = TRUE
    
    strFileName = request("file")
    action = "" & request("act")
    sUrl = "http://10.39.144.28/customers/programs/certificati/content/down.asp?file=" & strFileName
    
    HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
    HTTPREQUEST_SETCREDENTIALS_FOR_PROXY  = 1
    
    iAttempts = 0
    bDone = false
    Dim objWinHttp
    Dim strHTML
    
    Set objWinHttp = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
    objWinHttp.Open "GET", sURL, False
    Do
       iAttempts = iAttempts + 1
       objWinHttp.Send
       Select Case objWinHttp.Status
       Case 200
            bDone = True
       Case 401
            objWinHttp.Open "GET", sURL, False
            objWinHttp.SetCredentials "", "", HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
       Case 407
            objWinHttp.Open "GET", sURL, False
            objWinHttp.SetCredentials "", "", HTTPREQUEST_SETCREDENTIALS_FOR_PROXY
       End Select
    Loop Until bDone Or (iAttempts > 3)
    
    Response.ContentType = objWinHttp.GetResponseHeader("Content-Type")
    'response.Write objWinHttp.GetResponseHeader("Content-Type")
    'response.end
    strHTML = objWinHttp.ResponseBody
    
    'EXTDATO : settaggio HTTP Header documenti
    '*************************************************************
    arrFile = split(strFileName, ".")
    strFileExt = LCase(arrFile(UBound(arrFile)))
    select case strFileExt
    	case "pdf"
    		strMIME = "application/pdf"
    	case "doc"
    		strMIME = "application/msword"
    	case "xls"
    		strMIME = "application/vnd.ms-excel"
    	case "zip"
    		strMIME = "application/zip"
    		action  = "D"
    	case "tif"
    		strMIME = "image/tiff"
    	case else
    		strMIME = "application/octet-stream"
    end select
    'strMIME= "application/octet-stream"
    Response.ContentType = strMIME
    if action = "D" then 'Download
    	Response.AddHeader "Content-Disposition", "attachment; filename=""" & strFileName & """"
    elseif action = "V" or action = "" then 'View
    '	Response.AddHeader "Content-Description", """" & arrFile(0) & """"
    '	Response.AddHeader "Content-Disposition", "inline; filename="&arrFile(0)
    end if
    
    '*************************************************************
    
    Response.BinaryWrite(strHTML)
    
    Response.CacheControl = "public" 
    Set objWinHttp = Nothing
    set obj = Nothing
    %>
    La pagina fa una richiesta HTTP di una pagina che sta su un altro server e recupera il file . Dopodichè setta il content type in modo opportuno.

    Che manca ??? :master:

  4. #4
    se vuoi che si apra nel broser non devi usare content-disposition attach ma


    '--- Content-Disposition tells the browser how to handle the file, and what the name
    '--- of the file is. The "inline" option tells the browser to open the Word doc
    '--- in the browser.
    Response.AddHeader "Content-Disposition", "inline;filename=""" & strFileName & """"


    http://support.softartisans.com/docs...g_download.htm

  5. #5
    broser? devo cambiare tastiera!!!


  6. #6
    In teoria faccio già cosi mi pare . . . :master:

    Se guardi in fondo , in caso l'action è "D" (download) eseguo il download , viceversa se "V" eseguo la visualizzazione . . .

    Sbaglio ???

  7. #7
    codice:
    if action = "D" then 'Download
    	Response.AddHeader "Content-Disposition", "attachment; filename=""" & strFileName & """"
    elseif action = "V" or action = "" then 'View
    '	Response.AddHeader "Content-Description", """" & arrFile(0) & """"
    '	Response.AddHeader "Content-Disposition", "inline; filename="&arrFile(0)
    end if
    a me le righe sembrano commentate!!!???

  8. #8
    Corretto con :

    codice:
    if action = "D" then 'Download
    	Response.AddHeader "Content-Disposition", "attachment; filename=""" & strFileName & """"
    elseif action = "V" or action = "" then 'View
    Response.AddHeader "Content-Disposition", "inline;filename=""" & arrFile(0) & """" 
    
    end if
    Ora anche il PDF in visualizzazione mi mostra la schermata di download, ricommentando la riga appena aggiunta si torna alla situazione di prima , ovvero solo PDF , GIF e BMP vengon visualizzati

  9. #9
    mistero della fede ....


    fatti stampare il contenuto di action ....

  10. #10
    Quello son sicuro che è corretto perchè lo passo manualmente da querystring in quanto la mia è una pagina di prova . . .

    L'unica cosa che mi fa pensare è che nella pagina che chiamo da remoto vengan settati degli header che vengon memorizzati . . .

    Ora do un occhio . . .

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.