Skip to content

Instantly share code, notes, and snippets.

Created November 26, 2017 03:42
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 anonymous/8107c16078ad5c551236f11f1159d621 to your computer and use it in GitHub Desktop.
Save anonymous/8107c16078ad5c551236f11f1159d621 to your computer and use it in GitHub Desktop.
# html
<div>
<form action="/files_upload" method="post" enctype="multipart/form-data">
<div class="section3">
<br>
<input type="submit" class="button" value="<%= translate 'upload_file_button' %>">
<label for="file_upload" class="button">
<input id="file_upload" type="file" name="file" multiple>
</label>
</div>
</form>
</div>
# Route
$logged_in->post('/files_upload')->to('files#upload');
# Controller code
sub upload {
my $self = shift;
my $dir = $self->param("dir");
my $file_dir = $self->param("file_dir");
my $back = url_escape( $self->param("back") );
my $xpath = $self->param("xpath");
my $select_files = $self->param("select_files");
my $filter = $self->param("filter");
$self->render( text => "Request too big", status => 200 )
if $self->req->is_limit_exceeded;
for my $file ( @{$self->every_param("file")} ) {
# skip if filename is empty or filename does not match with filter
next if $file->filename =~ /^ *$/;
next if $file->filename !~ /$filter/;
my $dest_path = $file_dir . "/" . $file->filename;
$file->move_to( $dest_path );
}
$self->redirect_to("*****hidden*****");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment