Created
February 2, 2010 17:22
-
-
Save sharifulin/292838 to your computer and use it in GitHub Desktop.
Mojo uploads
This file contains hidden or 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
#!/usr/bin/env perl | |
use lib '../mojo/lib'; | |
BEGIN { $ENV{MOJO_TMPDIR} = 'tmp/upload' }; | |
use Mojolicious::Lite; | |
use Data::Dumper; | |
get '/' => 'form'; | |
post '/' => sub { | |
my $self = shift; | |
{ | |
open my $fh, '>', 'r'; | |
print $fh $self->req; | |
} | |
if (my $u = $self->req->upload('file')) { | |
warn $u->filename; | |
$self->stash($u->name => $u->filename); | |
} | |
if (my $u = $self->req->upload('image')) { | |
warn $u->filename; | |
$self->stash($u->name => $u->filename); | |
} | |
} => 'form'; | |
shagadelic(split /\s/, 'daemon --reload --listen http://*:6006 --pid tmp/test.pid --lock tmp/test.lock'); | |
__DATA__ | |
@@ form.html.ep | |
% layout 'main'; | |
<form method="post" enctype="multipart/form-data"> | |
<input name="image" type="file" /> | |
<input name="file" type="file" /> | |
<input type="submit" /> | |
</form> | |
<pre> | |
%= dumper($self->{stash}); | |
</pre> | |
@@ layouts/main.html.ep | |
<h1>Test</h1> | |
<%== content %> | |
<p>Test!</p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment