Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generating images for multiple users 2

Status
Not open for further replies.

philote

MIS
Oct 2, 2003
861
US
I have as script that generates an image based on user input and also generates the html to display that image (using an img tag). The problem is, the script always saves the image with the same filename. So if two users generate an image at approximately the same time, one could end up getting the image generated based on the other's input. While I don't see this happening often (if ever) for my script, I do want to avoid this if at all possible. I just can't think of a good way to do it. Sure, I can use a random file name each time the image and html are generated, but then I'd need some sort of clean-up script to run periodically to delete those images. Are there any other options?

 
What do your visitors do with the image/html after it's generated? My thinking is that you could save the file using the username+date+time as it's name (or whatever), attach the image/html to an email and send, then delete the file after the email has been sent. This would eliminate the need to hold the file for future use as well as any clean-up processes later on.

There's always a better way. The fun is trying to find it!
 
My thought is to use some fixed number of files, say 10. Use a For/Next type loop to increment the filename, then start at the beginning again. Of course you could still have the same problem if 10 (or whatever number) users access at the same time.
 
tviman, that's a good idea, but it'd be easier for the user in this case to save the file from the web page. The image I'm generating is actually a upc barcode.

smah, good idea. This would work good in our case because I doubt we'd ever have more than a few users generating images at a time.

I was also thinking, since these are barcodes being generated for our company and we wouldn't have that many product id's, I could just save the image using a filename relating to the upc#. So if I had the upc 1234567890, the file name would be 1234567890.jpg. Then my script could check to see if that barcode has already been generated before generating it again.

 
That makes sense. I do something very similar with shipping labels - check to see if it exists, if not, then create it.
 
I may have to post this as a thread in the browser issues or html forum, but any idea how to keep IE from caching the image? I was testing in Mozilla and all was well but when I tried it in IE, the image would get generated the first time and IE would cache it and show that same UPC every time after that. I've searched and tried every meta tag I could find but IE still won't cooperate.

 
Now you're in trouble. Hope you've got time for some reading. See the links in:

cashing problem
thread608-841600
 
philote - saving the UPC to a file is an idea but I wonder if you would have as much overhead/processing time as if the user just created when needed. I did that when I was doing work for teh True Value Hardware distribution system - 88,000 items with as many as 4 levels of UPC numbers per item (mater pack, inner pack, sales pack, individual item).

Rather than save the image I just pulled the appropriate UPC from the master inventory file and ran it thru a laser printer that had a barcode printing module attached.

As far as keeping the image "safe" on your HTML page - forget it! Can't be done so don't waste your time. trust me on this - I've broken every attempt ever tried in less than 2 minutes - and most of the time in less than 10 seconds.

There's always a better way. The fun is trying to find it!
 
Not caching pages

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">


bitten me in the ass before, any page with pricing information should have these directives

HTH
--Paul
 
Paul, thanks for the info but unfortunately I'd already tried that and it still seems to be caching. I wonder if the problem relates to this page being a .html page, even though it is really being processed by the webserver as a script. I had to change the form method to 'get' before IE would even show an image after you submitted the form... it seemed to be caching the entire page. Now it's just caching the image.

tviman, this system won't be used all that much so I'm not too concerned about disk space or processing time. My main concern is that the user gets the image for the UPC they typed in. Not a cached image and not an image someone else generated. Hopefully saving the image using the upc as filename will alleviate both problems.
I'm not concerned about images being stolen as this is for our intranet. But I know how hard it is to secure images when that dang PrintScreen button exists ;-)

 
Did anyone read the follow the links in the other thread that I posted? Even MS agrees that there are problmes using the Meta tag above. Because we are discussing this in the CGI forum, check the CGI section of
 
If I understand your question correctly, you call a script with a set of parameters. The script generates and stores an image on your server, say as tempfile.gif, and returns a snippet of HTML:
Code:
<img src="/images/tempfile.gif">

I suggest taking a different approach altogether. Write a new script that accepts its parameters and simply returns the resulting image. You'd then call it from inside your image tag like this:
Code:
<img src="/cgi-bin/myscript.cgi?upc=12345">
When returning the image you'll need to send the right MIME type - "image/gif" or whatever. I can't offer more specific advice without knowing more about what you're using.

Your existing script would just have to generate this <img> tag including the relevant parameters in the src attribute.

You can see a script-generated image at . The map is built up on-the-fly from a database, and is simply requested as an image:
Code:
<IMG SRC="/cgi-bin/bigmap.pl" WIDTH=456 HEIGHT=552 BORDER=0 USEMAP="#map" ALT="Group Locations">


-- Chris Hunt
 
That may be the way to go, Chris. Thanks for the advice. I'm using Apache with mod_perl and the scripts are writtin in Perl using HTML::Mason. Doing a quick search it looks like I can set the MIME type using the request object's content_type function, but I'll give it a shot and see.

 
Got it working! I had some problems with Image::Magick (due to lack of documentation.. go figure) but it's going now. I had to convert the image that I was previously writing to disk to an Image::Magick blob like this:
Code:
my @blobs = $final->ImageToBlob(magick=>'jpg');
Then send $blob[0] to the web browser. The part that took forever to figure out was to put in the magick=>'jpg' param.

Thanks again Chris!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top