Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,466
    Thanks
    15
    Thanked 0 Times in 0 Posts

    binary right an image

    How can I take a url and binary wite the image (so that it can be accessed in an img src with url of asp page)?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,176
    Thanks
    80
    Thanked 4,560 Times in 4,524 Posts
    Are you asking how you can do something like:
    <img src="getImage.asp?id=73" />
    ???

    If not, I don't understand the question at all.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Senior Coder
    Join Date
    May 2004
    Posts
    1,466
    Thanks
    15
    Thanked 0 Times in 0 Posts
    yes bit in getimage.asp if i put response.write and link --it doesn't work

    someone suggested I need to write it out as binary data?

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,176
    Thanks
    80
    Thanked 4,560 Times in 4,524 Posts
    Yes, it's not hard.

    Assuming that you are using <img src="getImage.asp?id=73" /> you would need to do
    Code:
    <%
    ' make sure that the < in the above line is the FIRST CHARACTER in the ASP page!!!
    '
    ' what image was requested?
    imageid = CLNG( Request("id") )
    
    ... here you need to go find the image to match the imageid ...
    ... we will assume that you find some FILENAME, here called fname:
    fname = ... you supply this code ...
    
    ' Set the content type to the specific type that you are sending.
    ' Find the extension of the fname, thus:
    period = InStrRev(fname,".")
    If period = 0 Then Response.End
    fext = Mid(fname,period+1)
    
    ' Then tell the browse what the type is:
    Response.ContentType = "image/" & fext
    
    Set strm = Server.CreateObject("ADODB.Stream")
    strm.Open
    strm.Type = 1 ' binary stream
    
    ' assuming fname is *RELATIVE* to the current directory:
    strm.LoadFromFile Server.MapPath(fname)
    ' (omit the Server.MapPath if fname is already a full Windows path!)
    
    Response.BinaryWrite strm.Read ' write the entire image out to the browser
    
    strm.Close
    Set strm = Nothing
    Response.End ' important!
    %>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    esthera (02-03-2013)

  • #5
    Senior Coder
    Join Date
    May 2004
    Posts
    1,466
    Thanks
    15
    Thanked 0 Times in 0 Posts
    that worked --thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •