|
#!/usr/bin/perl $droot = "/home/"; $i=0; $title[$i]="pokemon"; $galt[$i]="pokemon"; $gale[$i]="pokemon"; $i++; $title[$i]="cartoon"; $galt[$i]="cartoont"; $gale[$i]="cartoone"; $i++; $title[$i]="streetfighter"; $galt[$i]="sft"; $gale[$i]="sfe"; $i++; $title[$i]="test"; $galt[$i]="g01t"; $gale[$i]="g01e"; $i++; $imax=$i-1; &parse_form; for $j(0..$imax) { if ($v{'cat'} eq $title[$j]) { $gal=$j; } } $gdire=join '',"/",$gale[$gal],"/"; &getf; print"Content-type:text/html\n\n"; print'<html><head><base target=_blank></head><body>'; $trowcol = $v{'row'} * $v{'col'}; $tot_page = ($tot_pro - ($tot_pro % $trowcol)) / $trowcol + 1; if ($v{'res'} eq '800') { if ($v{'col'} eq '6') {$wd = 100;} if ($v{'col'} eq '7') {$wd = 85;} if ($v{'col'} eq '8') {$wd = 75;} } if ($v{'res'} eq '1024') { if ($v{'col'} eq '6') {$wd = 130;} if ($v{'col'} eq '7') {$wd = 110;} if ($v{'col'} eq '8') {$wd = 100;} } print"<form action=gallery.pl action=post target=_top>"; if (!$v{'file'}) { print'<table width=100% border=1><tr><td>'; print'<select NAME=row SIZE=1>'; for $i (4..6) { print"<option value=$i "; if ($v{'row'} eq $i) { print'selected';} print">$i row"; } print'</select></td><td align=center>'; print'<select NAME=col SIZE=1>'; for $i (6..8) { print"<option value=$i "; if ($v{'col'} eq $i) { print'selected';} print">$i col"; } print'</select></td><td align=center>'; print'<select NAME=res SIZE=1>'; print'<option value=800 '; if ($v{'res'} eq '800') { print'selected';} print'>800*600'; print'<option value=1024 '; if ($v{'res'} eq '1024') { print'selected';} print'>1024*768'; print'</select></td><td align=center>'; print'<select NAME=seq SIZE=1>'; print'<option value=asc '; if ($v{'seq'} eq 'asc') { print'selected';} print'>Ascending'; print'<option value=des '; if ($v{'seq'} eq 'des') { print'selected';} print'>Descending'; print"</select></td><td>$v{'page'} of $tot_page</td><td>", $v{'row'}*$v{'col'}; print" Pic/Page</td><td>$tot_pro Total Pic</td></tr></table>"; } print'<table width=100% border=1><tr><td valign=top width=100>'; print"<input type=submit value='Go gallery'>"; print'<select NAME=cat SIZE=8>'; for $i(0..$imax) { print"<option value=$title[$i]"; if ($title[$gal] eq $title[$i]) { print" selected";} print">$title[$i]"; } print"</select>$hr เลือกหน้า<br>"; for $i(1..$tot_page) { print'<input type=submit name=page value=',$i,'> '; } print'</form></td><td bgcolor=#fffffd align=center valign=top>'; print'<table width=100%><td>'; if ($v{'file'}) { print"<center><img src=$gdire$v{'file'}></center>"; } else { for $i(1..$trowcol) { $p = $v{'page'}*$trowcol-$trowcol+$i-1; if ($p<10) { $p=join'','00',$p; } else { if ($p<100) { $p=join'','0',$p; }} if ($p < $tot_pro) { @filetr = split ("\/",$okr[$p]); $filet = $filetr[@filetr - 1]; print'<a href=gallery.pl?cat=',$v{'cat'},'&file=',$filet; print'><img border=0 src=',$okr[$p],' width=',$wd,'></a> ',"\n"; } } } print'</td></table></td></tr></table></body></html>'; sub parse_form { if ($ENV{'REQUEST_METHOD'} eq 'GET') { @pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); } foreach $pair (@pairs) { local($name, $value) = split(/=/, $pair); $v{$name} = $value; } if (!$v{'cat'}) { $v{'cat'}=$title[0]; } if (!$v{'seq'}) { $v{'seq'}='asc'; } if (!$v{'res'}) { $v{'res'}=800; } if (!$v{'col'}) { $v{'col'}=6; } if (!$v{'row'}) { $v{'row'}=4; } if (!$v{'page'}) { $v{'page'}=1; } } sub getf{ $gdirt=join '',$droot,$galt[$gal],"/."; opendir(click,"$gdirt"); @allf = readdir click; closedir(click); for $i (0 .. @allf) { $r4 = lc substr($allf[$i],length($allf[$i])-4,4); if (length($allf[$i]) > 4 and ($r4 eq ".jpg" or $r4 eq ".gif")) { $pp = join '',"/",$galt[$gal],"/",$allf[$i]; push @okr,$pp; } } if ($v{'seq'} eq "des") { @okr = reverse sort @okr; } $tot_pro = @okr; } |