Skip to content

Commit

Permalink
Updated Perl example to handle form-based uploads for older browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Healy committed Sep 8, 2012
1 parent 9f11815 commit 43cb6bd
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions server/perl.cgi
Expand Up @@ -12,7 +12,13 @@
use CGI;
my $IN = new CGI;

my $file = $IN->param('POSTDATA');
my $file;
if ($IN->param('POSTDATA')) {
$file = $IN->param('POSTDATA');
} else {
$file = $IN->upload('qqfile');
}

my $temp_id = $IN->param('temp_id');

# make a random filename, and we guess the file type later on...
Expand All @@ -38,8 +44,15 @@

mkdir("$uploaddir/$temp_id");

binmode(WRITEIT);
open(WRITEIT, ">$uploaddir/$name.$type") or die "Cant write to $uploaddir/$name.$type. Reason: $!";
if ($IN->param('POSTDATA')) {
print WRITEIT $file;
} else {
while (<$file>) {
print WRITEIT;
}
}
close(WRITEIT);

my $check_size = -s "$uploaddir/$name.$type";
Expand All @@ -59,4 +72,4 @@
print qq|{ "success": true }|;

print STDERR "file has been successfully uploaded... thank you.\n";
}
}

0 comments on commit 43cb6bd

Please sign in to comment.