Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Mojolicious + fileuploader.js (http://valums.com/ajax-upload/)
- # Example for server side, compatible with IE6 ;)
- sub upload {
- my $self = shift;
- my %res = ();
- if ($self->req->upload('qqfile') || $self->req->body) {
- my $fh = File::Temp->new(
- TEMPLATE => 'X' x 12,
- UNLINK => 0,
- SUFFIX => '_' . time . '_orig.jpg',
- DIR => $self->app->home->rel_dir('public/fotos'),
- );
- if ($fh) {
- if ($self->req->upload('qqfile')) {
- close $fh;
- $self->req->upload('qqfile')->move_to($fh->filename);
- }
- else {
- print $fh $self->req->body;
- close $fh;
- }
- $res{success} = 'true';
- $fh = undef;
- }
- }
- my $json = Mojo::JSON->new;
- $self->render({text => $json->encode(\%res)});
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement