#!/usr/bin/perl -w use CGI::Carp qw(fatalsToBrowser); ############################################# $path_to_files = "/home/foo/www/dir"; $script = "$ENV{'QUERY_STRING'}"; ############################################# read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/\n/ /g;# added to strip line breaks $FORM{$name} = $value; } ############################################# print "Content-type: text/html\n\n"; $query = "$ENV{'QUERY_STRING'}"; if ($query eq "test") {&Display_Form} elsif ($FORM{'create_list'} eq "Create") {&Create_List} else {&Display_Form} #### BEGIN DISPLAY FORM #### sub Top { opendir DIR, "$path_to_files" or die "Can't open directory:$!\n"; @thefiles = sort(grep(/html$/, readdir(DIR))); closedir(DIR); $count = @thefiles; print ""; print "MY SIMPLE FILE SELECTOR"; print ""; print "

MY SIMPLE FILE SELECTOR

"; print "

The following [$count] files were found in the [$path_to_files] Dir.

"; print "
"; } sub Display_Form { &Top; print "
"; print ""; print "
"; print "
"; print "
  • Select from list
    "; foreach (@thefiles) { $choice = $_; print "$choice
    "; } print "

    "; print "
  • "; print "
    "; &Bottom; } sub Bottom { print "

    "; print "$footer"; print "
    "; } #### END DISPLAY FORM #### #### BEGIN CREATION PROCESS #### sub Create_List { $choice = "$FORM{'choice'}"; @choices = split(/,/, $choice); $selected = @choices; open FILE,">list.txt" or die "Can't open file:$!\n"; foreach (@choices) { print FILE "$choice\n"; } close FILE; &Finished; } sub Finished { &Top; print "

    List created

    "; print "You selected ($selected):
  • $choice

  • "; print "
    Go Back...
    "; &Bottom; } #### END PROCESS ####