in reply to Looking for a good Perl web slideshow script or module
#!/usr/bin/perl use warnings; use strict; $| = 1; my $boundary_string = "\n" . "--End" . "\n"; my $end_of_data = "\n" . "--End--" . "\n"; my $delay_time = 30; #seconds each is shown my $dir = 'images/'; #directory where images are my $pattern = '(.jpg)$'; #Filenames ending in .jpg opendir DIR, $dir or die "Cannot readdir $dir:$!\n"; my @files = grep /$pattern/,(readdir DIR); my @image_list= grep { $_ ne "." and $_ ne ".." } @files; closedir DIR; my $browser = $ENV{'HTTP_USER_AGENT'}; print<<EOH; Content-type: multipart/x-mixed-replace\;boundary=End EOH while(1){ for (my $loop=0; $loop < scalar (@image_list); $loop++) { &open_and_display_jpg ($image_list[$loop]); print $boundary_string; sleep ($delay_time); } } print $end_of_data; exit(0); sub open_and_display_jpg { my $file = $_[0]; if ( (open (FILE, "< $dir$file")) ) { my $content_length = (stat (FILE))[7]; print<<EOF; Content-type: image/jpg Content-length: $content_length EOF binmode FILE; print <FILE>; close (FILE); } else { #&return_error (500, "File Access Error", print "Cannot open graphic file $file!"; } }
|
|---|