| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Maypole::Plugin::Upload; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION='0.02'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
33
|
1
|
|
888
|
use constant APACHE2 => $mod_perl::VERSION && $mod_perl::VERSION >= 1.99; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
348
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
if (APACHE2) { |
|
8
|
|
|
|
|
|
|
require Apache2; |
|
9
|
|
|
|
|
|
|
require Apache::Upload; |
|
10
|
|
|
|
|
|
|
} |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub upload { |
|
13
|
0
|
|
|
0
|
1
|
|
my ($r,$field) = @_; |
|
14
|
0
|
|
|
|
|
|
my ($filename,$fh,$content,$mime); |
|
15
|
0
|
0
|
|
|
|
|
if ($r->{ar}) { |
|
|
|
0
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
my $au=$r->{ar}->upload($field); |
|
17
|
0
|
|
|
|
|
|
$filename=$au->filename; |
|
18
|
0
|
|
|
|
|
|
$fh=$au->fh; |
|
19
|
0
|
|
|
|
|
|
$mime=(APACHE2 ? $au->info->{"Content-type"} : $au->info("Content-type")); |
|
20
|
|
|
|
|
|
|
} elsif ($r->{cgi}) { |
|
21
|
0
|
|
|
|
|
|
$filename=$r->{cgi}->param($field); |
|
22
|
0
|
|
|
|
|
|
$fh=$r->{cgi}->upload($field); |
|
23
|
0
|
0
|
|
|
|
|
$mime=(ref $r->{cgi} eq "CGI" ? |
|
24
|
|
|
|
|
|
|
$r->{cgi}->uploadInfo($filename,'mime') : |
|
25
|
|
|
|
|
|
|
$r->{cgi}->upload_info($filename,'mime') ); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
} else { |
|
28
|
0
|
|
|
|
|
|
die("File uploads not supported"); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
0
|
|
|
|
|
|
$content=do { local $/; <$fh> }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
warn "Got Content-length:".length($content); |
|
32
|
0
|
0
|
|
|
|
|
return (wantarray ? ( filename=>$filename, |
|
33
|
|
|
|
|
|
|
content =>$content, |
|
34
|
|
|
|
|
|
|
mimetype=>$mime ) : $content); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
1; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 NAME |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Maypole::Plugin::Upload - Handle file uploads in Maypole |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my %upload = $r->upload('file'); |
|
45
|
|
|
|
|
|
|
return unless $upload{mimetype} =~ m|^image/|; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
This plugin adds a upload method to your Maypole request object to allow |
|
50
|
|
|
|
|
|
|
you to access file uploads in a platform neutral way. |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 METHODS |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=over 4 |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item upload |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
This method takes the form name as parameter, and returns either a hash |
|
60
|
|
|
|
|
|
|
with 'content', 'filename' and 'mimetype', or the content if used |
|
61
|
|
|
|
|
|
|
in scalar context. |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=back |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 AUTHOR |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Marcus Ramberg C |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 LICENSE |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
You may distribute this code under the same terms as Perl itself. |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |