All pastes #909199 Raw Edit

Untitled

public text v1 · immutable
·published 2008-02-18 23:39 UTC
rendered paste body
#!/app/gmd/bin/perl
use strict;
use CGI;

my $upload_dir = "/tmp";

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year += 1900;
$mon++;
my $timestamp = sprintf("%4d-%2.2d-%2.2d-%2.2d:%2.2d:%2.2d",$year,$mon,$mday,$hour,$min,$sec);

my $query = new CGI;
if ( $query->param("import_file") eq "" )  { exit };
my $filename = $query->param("import_file");
$filename =~ s/.*[\/\\](.*)/$1/;
$filename = $timestamp."-".$filename;

my $upload_filehandle = $query->upload("import_file");

open UPLOADFILE, ">$upload_dir/$filename";
binmode UPLOADFILE;
while ( <$upload_filehandle> )
{
        print UPLOADFILE;
}
close UPLOADFILE;

#my $goodies;
#open UPLOADFILE, "$upload_dir/$filename";
#while ( <UPLOADFILE> ) {
#       $goodies .= $_;
#}
#close UPLOADFILE;

print $query->header ( );
opendir DIR , $upload_dir or die "Flaming death! No Upload folder! : $!\n";

my @removedfiles;
my $fullpath;
foreach my $file ( readdir(DIR) ) {
        $fullpath = "$upload_dir/$file";
        if ( -f $fullpath ) {
        my $time = (stat($fullpath))[9];
                #print "$fullpath ".localtime(time)." - ".localtime($time)." > 6 <br>";
                if (  time - $time > ( 60*60*24*180 ) ) {   # s->min->h->day * 180
                        unlink $fullpath;
                        push ( @removedfiles, $file );
                }
        }
}
my $delfiles = join ( "<BR>", @removedfiles);

print <<END_HTML;

<HTML>
<HEAD>
<TITLE>File Uploaded Successfully</TITLE>
</HEAD>
<BODY>

<P>Thanks for uploading your file, it's saved to '$filename'! </P>
<P>Your file:<a href="/upload/$filename">$filename</a></P>
<P>Go to the upload directory:<a href="/upload/">Uploads</a></P>
<P>Files Removed from upload folder for being older than 180 days :</P>
$delfiles
</BODY>
</HTML>

END_HTML