Forum Moderators: open

Message Too Old, No Replies

Help with Binary Read/Write

         

nwhorton

4:19 pm on Apr 15, 2005 (gmt 0)

10+ Year Member



Hey,
So I'm working on this script to randomize images in a .css file (big topic on it in the css section actually)
but I've decided to try to change the script to make it open and read the image as a binary file...heres the randomization script:

<%@ Language="VBScript" %>
<% Option Explicit %>
<%
Function cssImageLocation
Dim location
Randomize
location = "images/test/" & INT((7)*RND()) & ".jpg"
location = "http://www.example.com/" & location
cssImageLocation = location
End Function
%>

And here is what I was thinking for pseudocode...

pick random image file name
Response.ContentType = "image/jpeg"
open the file as a binary file
print the contents of the file to the Response
close the file

Can anyone give me some help with the opening and printing of the binary file though? Thanks!

[edited by: Xoc at 12:21 am (utc) on April 16, 2005]
[edit reason] no urls [/edit]

mrMister

4:28 pm on May 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can anyone give me some help with the opening and printing of the binary file though? Thanks!

I went through this a few years back, and came to the conclusion that it couldn't be done. I forget the reasons, but I think it was because you can't write binary data to the ASP Response object.

The workaround in ASP is to point your HTML to a page that Response.redirects to the image you want.

I think it can be done is ASP.Net however.

TheNige

7:59 pm on May 10, 2005 (gmt 0)

10+ Year Member



actually...i've done something like this using a 3rd part control a long time ago....but the src of the Image was actually the asp page that your wrote the binary to just like you had in the pseudo code...

<img src=RandomPicture.asp>

TheNige

8:01 pm on May 10, 2005 (gmt 0)

10+ Year Member



also, you can make your CSS file have a ".asp" extension and you can then run asp script in it...so you could actually change the image path in there dynamically.

you would just make your link go to yourcss.asp instead of yourcss.css