Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Commit

Permalink
Merge pull request #318 from MattHealy/perl-form-upload
Browse files Browse the repository at this point in the history
Updated Perl example to handle form-based uploads for older browsers
  • Loading branch information
Ray Nicholus committed Sep 9, 2012
2 parents 9f11815 + 43cb6bd commit 1bbfa09
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 1bbfa09

Please sign in to comment.