The Blog of Brad
subs.pl // Subroutines
#Subroutines sub epoch_to_datef{ ##requires use Time::gmtime; in header ($seconds, $minutes, $hours, $day_of_month, $month, $year, $wday, $yday, $isdst) = localtime($results[6]); if (length $minutes == 1){ $minutes = sprintf("%02d", $minutes); $minutes=~ tr/ /0/; } if (length $month == 1){ $month = sprintf("%02d", $month); $month=~ tr/ /0/; } if (length $day_of_month == 1){ $day_of_month = sprintf("%02d", $day_of_month); $day_of_month=~ tr/ /0/; } $hours += 4; if (length $hours == 1){ $hours = sprintf("%02d", $hours); $hours=~ tr/ /0/; } $year+=1900; $Month++; $dt = $hours . ":" . $minutes . " " . $day_of_month . "/" . $month . "/" . $year; return $dt; } sub printHeader { $_ = shift; "Content-type: text/html\n\n"; print "$_
"; } sub printFooter { ##requires use Time::HiRes qw(gettimeofday tv_intverval); in header $t1 = [gettimeofday]; $time = tv_interval($t0,$t1); print "This page was generated in " . $time . " seconds. "; } sub randomPassword {#from paulbradley.tv/30 my $password; my $_rand; my $password_length = $_[0]; if (!$password_length) { $password_length = 10; } my @chars = split(" ", "a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9"); srand; for (my $i=0; $i <= $password_length ;$i++) { $_rand = int(rand 41); $password .= $chars[$_rand]; } return $password; } sub connectDB{ require "vars.pl"; my $dbh = DBI->connect($dsn, $username, $password) or die "couldn't make DBH: " . $dbh->errstr; undef $db_usr, $db_pswd, $dsn, $database; } sub setMessage{ $_ = shift; if($_ == 1){ ##noname and thensome return " There are many things that may have gone wrong with this file upload:
Hope this helps! With Love,Brad "; }elsif($_ == 2){ ##Short code timeout return " There was one thing that happened to make this fail this time:
- There is a file-size limit of
10MB per file. (That's10*(1024^3) )- You may have forgot to select a file in the previous page as the filename that came through was
$filename .- Something may have gone wrong with the internet connection.
- You're browser may have messed something up (especially if you're using IE!)
- These fine-ass servers at Dreamhost may have failed you and ME.
- It may be possible that this script failed. Just maybe. ;P
Hope this helps! With Love,Brad "; }elsif($_ == 3){ return " " } } sub Say{ $_ = shift; return ("\n $_ \n"); }
- Imma level with you: I use a script to come up with a unique code to distinguish one file from another regardless of it's name, size, etc... And that times out after a number of tries, in this case it just ran
" . $x-1 . " times. So, to move on from here, just hit the refresh button in your browser ORF5 orCTRL-R on Windows,Command-R on the Mac. The Linux key command depends on the browser and distro.

















No comments yet.
Comments are closed.