Last active
August 10, 2016 14:16
-
-
Save dmr3/c11672384aeed51084076183a7d9d492 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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