全部博文(1144)
分类: LINUX
2009-12-09 12:02:30
#!/usr/local/bin/perl # Simple Gallery v.06b # Copyright 2006-2008 Jeremy Kister use strict; use CGI qw(:standard -nosticky); use CGI::Carp ('fatalsToBrowser'); my $q = CGI->new; my $me = $ENV{'SCRIPT_NAME'}; my $dir = $q->param('dir'); die "dir: $dir\n" if($dir =~ /\.\./); die "private area\n" if($dir =~ /private\//); my $id = $q->param('id') || '1'; die "id: $id\n" unless($id =~ /^\d+$/); my $path = $ENV{'DOCUMENT_ROOT'} . '/' . $dir; print $q->header(-expires=>'now'), $q->start_html('Simple Gallery'); my (%files,%thumbs); if(opendir(DIR, $path)){ my $i = 1; foreach my $obj (sort grep {/\.(?:jpe?g|gif|png)/i} readdir DIR){ unless(-d "$path/$obj"){ $files{$i} = $obj; if(-s "$path/thumbnails/$obj"){ $thumbs{$i} = $obj; } } $i++; } closedir DIR; my $x = ($id + 1); my $next = (exists($files{$x})) ? $x : 1; my $thumb = ( $thumbs{$id} && (! $q->param('nothumb')) ) ? 'thumbnails/' : ''; print '', "\n", '[ Back', "\n", ' | Enlarge', "\n", ' | Next ]', "\n", " ${thumb}$files{$id}\n", "
\n", '', "\n", '
', "\n", "\n"; }else{ print "could not open directory: $path: $!\n"; } print $q->end_html();