line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package meon::Web::Form::FileUpload; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
12286436
|
use File::Copy 'copy'; |
|
2
|
|
|
|
|
5696
|
|
|
2
|
|
|
|
|
308
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
577
|
use HTML::FormHandler::Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
extends 'HTML::FormHandler'; |
7
|
|
|
|
|
|
|
with 'meon::Web::Role::Form'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has '+name' => (default => 'form-file-upload'); |
10
|
|
|
|
|
|
|
has '+widget_wrapper' => ( default => 'Bootstrap' ); |
11
|
|
|
|
|
|
|
has '+enctype' => ( default => 'multipart/form-data'); |
12
|
|
|
|
|
|
|
#sub build_form_element_class { ['form-horizontal'] }; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has_field 'file' => ( |
15
|
|
|
|
|
|
|
type => 'Upload', required=>1, label => '', |
16
|
|
|
|
|
|
|
max_size => 1024*10_000, |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has_field 'submit' => ( |
20
|
|
|
|
|
|
|
type => 'Submit', |
21
|
|
|
|
|
|
|
value => 'Upload', |
22
|
|
|
|
|
|
|
css_class => 'form-row', |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub submitted { |
26
|
|
|
|
|
|
|
my ($self) = @_; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $c = $self->c; |
29
|
|
|
|
|
|
|
my $upload = $self->field('file')->value; |
30
|
|
|
|
|
|
|
my $upload_to = $self->get_config_folder('upload-to'); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
unless (-e $upload_to) { |
33
|
|
|
|
|
|
|
$upload_to->mkpath || die 'failed to create archive folder - '.$upload_to; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
copy($upload->tempname, $upload_to->file($upload->filename)) || die 'failed to copy file to archive - '.$!; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$self->detach; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
no HTML::FormHandler::Moose; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |