#!/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'); my ($ex) = ($fh =~ m|(\.[^./\\]+)$|); # 拡張子 if ($fh ne "") { 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}; } print $q->start_multipart_form(-name => 'myform'), $q->filefield(-name => 'uploaded_file'), $q->submit("OK"), $q->endform; my @fl = reverse <$outputdir/[0-9]*>; print ""; print $q->end_html(), "\n";