#!/usr/bin/env perl use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use POSIX qw(strftime); my $q = new CGI; print $q->header(), $q->start_html(); #print $q->dump; # for debug my $outputdir = "log"; # ファイルを置く先 (ディレクトリ) my $fh = $q->param('uploaded_file'); if ($fh ne "") { my ($ex) = ($fh =~ m|(\.[^./\\]+)$|); # 拡張子 my $tag = $q->param('tag'); ## $ex = $tag.$ex if ($tag ne "" and $tag =~ /^[A-Z0-9_-]+$/i); ## my $timestamp = strftime "%y%m%d%H%M%S", localtime; my $outputfn = "$outputdir/$timestamp$ex"; open(F, "> $outputfn") or die; flock(F, 2); if (defined $fh) { while (<$fh>) { print F $_; } } close F; print qq{saved as $outputfn}; } $q->delete_all(); print $q->start_multipart_form(-name => 'myform'), "FILE ", $q->filefield(-name => 'uploaded_file'), $q->submit("OK"), $q->br, "TAG ", $q->textfield(-name => 'tag'), ## "(Use [A-Za-z0-9_-] only. Ex. tmp -> 040101123456tmp.txt)", ## $q->endform; my @fl = reverse <$outputdir/[0-9]*>; print ""; print $q->end_html(), "\n";