Web Hosting Talk







View Full Version : Perl image display without SSI


Qacer
02-10-2003, 03:52 AM
Hello all,

I'm curious. Is there a Perl script that is able to randomly display images without the use of SSI? I'm specifically looking for a script that will allow me to do this <IMG SRC="www.mysite.com/cgi-bin/randompic.pl"> . Thanks!

LizMarr
02-10-2003, 04:48 AM
There are a bunch out there that do what is called a "slide show", some are very simple and do use random calls. A web search for "slideshow perl script" will give you a good start.



I'm not sure what you mean by "not using SSI"?

Qacer
02-10-2003, 01:31 PM
Hello LizMarr,

Actually, that's not what I'm looking. I just want a script that will open a random image from my server and output it. It's like having the script as the actual image file.

SSI is the abbreviation of server-side includes. These files usually end with a *.shtml. From my experience, they are very useful with news updates. I can just edit the text file with the new additions and not have to touch the html page.

luxline
02-10-2003, 01:39 PM
Possible options:

javascript/dhtml/flash?

Perl without SSI, no sorry, that wont work.

I assume your host doesnt allow ssi, well, if they allow .htaccess, and have overlooked a few security precautions, you can enable ssi in ordinary .html files. Goto apache.org and search for ssi/htaccess.

Good luck, if you get any closer, get back to me if you're stuck.

Years ago I tried the same thing as you're trying now, and remember taking days searching for an answer, which never came.

Qacer
02-10-2003, 01:59 PM
I found some leads on Expert Exchange. There were similar questions being entertained in their forums. Fortunately, I was able to cut and paste some various codes, but I'm trying to figure out why it doesn't run on my server.


#!/usr/bin/perl

$imagedir="/home/sites/site83/html/bucs";
opendir (IMDIR,"$imagedir");
@files=readdir (IMDIR);
closedir (IMDIR);
$i=0;

#get gif images listing
foreach $_ (@files)
{s/\n\r$/\n/;
if(/\.jpg$/)
{$i++;
push(@giffiles,$_);
}
}

srand(time ^ $$);
$num=rand(@giffiles);

print "Content-Type: image/jpg\r\n\r\n";

open IMAGE,"$imagedir/@giffiles[$num]") || die("Can't open file @giffiles[$num]";

binmode IMAGE;
binmode STDOUT;
print <IMAGE>;

close(IMAGE);


This supposedly allows me to be able to use the following tag:
<IMG SRC="http://www.site.com/cgi-bin/image.pl">

A similar technique has been used by other sites that want to protect their image paths from other users. I know this type of script will help me protect my Ebay auction images. I had problems with some sellers directly using my image paths from my server.

luxline
02-10-2003, 02:13 PM
Yes that should work. But thats not perl and ssi, thats just perl in a cgi area.

Just try the URL directly in your browser

http://<YOURDOMAIN>/cgi-bin/image.pl

and see what you get.

You can also embed the image in your html page. Dont know the specifics on that one, but again, it will hide the actual image URL.

If you had access to .htaccess files, this could all be done SERVER-WIDE with a few lines of code. No ssi/cgi/perl messing.

Oh, one other thing, when you upload your image.pl file, you have to change its MODE, you can do this in most ftp software, change the file to mode 755. Otherwise it wont work at all.

LizMarr
02-10-2003, 03:13 PM
Originally posted by Qacer
A similar technique has been used by other sites that want to protect their image paths from other users. I know this type of script will help me protect my Ebay auction images. I had problems with some sellers directly using my image paths from my server.

Protecting images can get complicated. If you use something that prevents outside linking to files, then you can't do eBay (which requires outside links) There are some SQL scripts that store the image into a database and then assemble it when displaying, this is probably the most secure. You could also simply do something like put your web URL prominently across the image using a skinny enough font that doesn't detract from what you are displaying. This way anyone "burrowing" your images would either have to edit it to get rid of the text (and then they'd have to host it themselves) or they'd have to use your image with your contact information and they'd be advertising your stuff. One thing that I have done in the past is to break an image into many small pieces. My HTML would assemble them for viewing, but it makes it harder for someone to link to or borrow my images. (they don't want to deal with a bunch of little images to make one large one)

The reason I asked you what you meant about "no SSI" was that the whole way Perl and CGI work is that the methods needed to run the scripts are hosted on the server. Some folks might consider that "SSI".

Here's a collection of simular scripts, a couple of these might work:

http://www.totalscripts.com/pages/Perl_Scripts/Random_Images/

Here's one that says that it doesn't need SSI -

http://www.scriptarchive.com/rand_image.html

I could probably find some more, but you get the idea.

Qacer
02-11-2003, 02:51 AM
Thank you for the tips ! :)

I finally got it working. Here is the code:


#!/usr/bin/perl

$imagedir="/home/sites/site83/html/bucs";
opendir (IMDIR,"$imagedir");
@files=readdir (IMDIR);
closedir (IMDIR);
$i=0;

#get gif images listing
foreach $_ (@files)
{s/\n\r$/\n/;
if(/\.jpg$/)
{$i++;
push(@giffiles,$_);
}
}

srand(time ^ $$);
$num=rand(@giffiles);

print "Content-Type: image/jpg\r\n\r\n";

open (IMAGE,"$imagedir/@giffiles[$num]") || die "Can't open file @giffiles[$num]";

binmode IMAGE;
binmode STDOUT;
print <IMAGE>;

close(IMAGE);


Works like a charm!

luxline
02-11-2003, 02:58 AM
Happy campers, thats what we like. :) Glad you fixed it.