RE: Perl Script in Apache
From: White Hat [EMAIL PROTECTED] To: FreeBSD Users Questions freebsd-questions@freebsd.org Subject: Perl Script in Apache Date: Sat, 5 May 2007 12:17:39 -0700 (PDT) I tried to get an answer to this on the Apache forum, but unfortunately, I was not successful. Running Apache on a FreeBSD-6.2 machine, I am attempting to set up a web page that changes a specific image on a daily basis. I found a Perl script that is supposed to do this, but it seems to fail. All that is displayed is a red [X]. If I run the script from the command line, it works, as it should. Well, at least it displays the correct file name. I assume I am doing something wrong with the actual web page, or else I am incorrectly calling the Perl script. This is a commented version of the script. = To display an image simply use this in your HTML: img src=/usr/local/www/apache22/data/perl_script.pl #!/usr/local/bin/perl # find out the day of the year my $day_of_year = (localtime(time()))[7]; # define the path where the images live . is the current directory $path = /usr/local/www/apache22/data/pics; # read all the jpg, gif or png filenames from the directory into an array opendir(DIR, $path); @files = grep { /\.(jpg|gif|png)$/i } readdir(DIR); closedir(DIR); # sort the filenames alphabetically @files = sort( {lc $a cmp lc $b} @files); # count the number of images $no_of_images = scalar(@files); # Now the fun bit :) We loop through the images once before # repeating them in the same order. If we divide the current # number of day of the year by the number of images in the # directory we get the number of times have repeated the images. # We are interested in the remainder of this calculation (this # is calculated using the % operator). Note - there must be # less than 365 images in the directory! We need to subtract # one from this number because arrays start at zero not 1! if ( $no_of_images = $day_of_year ) { $image_to_use = ($day_of_year % $no_of_images)-1; } else { $image_to_use = $day_of_year-1; }; print Location: $files[$image_to_use]\n\n; = -- White Hat [EMAIL PROTECTED] Can't help you with your script, but there are many of these image rotation scripts free on the web -- hotscripts.com for example is a good place to look for all kinds of perl/php scripts IMHO. Good luck! Jack _ Download Messenger. Join the im Initiative. Help make a difference today. http://im.live.com/messenger/im/home/?source=TAGHM_APR07 ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: OT - Perl Script in Apache
in message [EMAIL PROTECTED], wrote White Hat thusly... Running Apache on a FreeBSD-6.2 machine, I am attempting to set up a web page that changes a specific image on a daily basis. I found a Perl script that is supposed to do this, but it seems to fail. All that is displayed is a red [X]. If I run the script from the command line, it works, as it should. Well, at least it displays the correct file name. ... To display an image simply use this in your HTML: img src=/usr/local/www/apache22/data/perl_script.pl ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ Note that here, value for src attribute, the file location which can be accessed through the web server is needed. If the Perl program spits that out, great. The program posted puts out additional junk as is. When you look at the source of the generated page where you use img tag, what do you actually see? You may need to employ SSI ... http://httpd.apache.org/docs/2.2/howto/ssi.html ... as in ... img src=!--#exec cmd=/path/to/perl_script.pl--- Do not forget to mark perl_script.pl executable. #!/usr/local/bin/perl # find out the day of the year my $day_of_year = (localtime(time()))[7]; # define the path where the images live . is the current directory Please either carefully reformat the program or post the original as is. As you had posted, this program will not even compile as the comments are not properly wrapped. ... print Location: $files[$image_to_use]\n\n; Does the image appear if you change the print argument to just the file name, as in ... print $files[$image_to_use]; (... for there is no need to generate a HTTP header (which could be considered erroneous) for your usage for the header has been already sent as part of the page presented containing the img tag)? - Parv -- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Perl Script in Apache
I tried to get an answer to this on the Apache forum, but unfortunately, I was not successful. Running Apache on a FreeBSD-6.2 machine, I am attempting to set up a web page that changes a specific image on a daily basis. I found a Perl script that is supposed to do this, but it seems to fail. All that is displayed is a red [X]. If I run the script from the command line, it works, as it should. Well, at least it displays the correct file name. I assume I am doing something wrong with the actual web page, or else I am incorrectly calling the Perl script. This is a commented version of the script. = To display an image simply use this in your HTML: img src=/usr/local/www/apache22/data/perl_script.pl #!/usr/local/bin/perl # find out the day of the year my $day_of_year = (localtime(time()))[7]; # define the path where the images live . is the current directory $path = /usr/local/www/apache22/data/pics; # read all the jpg, gif or png filenames from the directory into an array opendir(DIR, $path); @files = grep { /\.(jpg|gif|png)$/i } readdir(DIR); closedir(DIR); # sort the filenames alphabetically @files = sort( {lc $a cmp lc $b} @files); # count the number of images $no_of_images = scalar(@files); # Now the fun bit :) We loop through the images once before # repeating them in the same order. If we divide the current # number of day of the year by the number of images in the # directory we get the number of times have repeated the images. # We are interested in the remainder of this calculation (this # is calculated using the % operator). Note - there must be # less than 365 images in the directory! We need to subtract # one from this number because arrays start at zero not 1! if ( $no_of_images = $day_of_year ) { $image_to_use = ($day_of_year % $no_of_images)-1; } else { $image_to_use = $day_of_year-1; }; print Location: $files[$image_to_use]\n\n; = -- White Hat [EMAIL PROTECTED] Looking for earth-friendly autos? Browse Top Cars by Green Rating at Yahoo! Autos' Green Center. http://autos.yahoo.com/green_center/ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]