Skip to content

Instantly share code, notes, and snippets.

@dmr3
Last active August 10, 2016 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmr3/c11672384aeed51084076183a7d9d492 to your computer and use it in GitHub Desktop.
Save dmr3/c11672384aeed51084076183a7d9d492 to your computer and use it in GitHub Desktop.
use Mojolicious::Lite;
plugin CGI => [ "/cgi-bin/script" => "cgi-bin/forms/word_binner.pl " ];
# Upload form in DATA section
get '/' => 'form';
# Multipart upload handler
post '/upload' => sub {
my $c = shift;
# Check file size
return $c->render(text => 'File is too big.', status => 200)
if $c->req->is_limit_exceeded;
# Process uploaded file
return $c->redirect_to('form') unless my $example = $c->param('example');
my $size = $example->size;
my $name = $example->filename;
$example->move_to("foo.txt");
$c->render(text => "Thanks for uploading $size byte file $name.\n");
};
app->start;
__DATA__
@@ form.html.ep
<!DOCTYPE html>
<html>
<head><title>Upload</title></head>
<body>
%= form_for upload => (enctype => 'multipart/form-data') => begin
%= file_field 'example'
%= submit_button 'Upload'
% end
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment