Result:
found more than 723 distributions - search limited to the first 2001 files matching your query
( run in 1.478 )
CGI-Untaint-upload
view release on metacpan or search on metacpan
package CGI::Untaint::upload;
use strict;
use base 'CGI::Untaint::object';
sub _untaint {
my $self = shift;
1;
__END__
=head1 NAME
CGI::Untaint::upload - receive a file upload
=head1 SYNOPSIS
my $handler = CGI::Untaint->new( map { $_ => $cgi->param($_) } $cgi->param);
# NOT my $handler = CGI::Untaint->new( $cgi->Vars ); !
$file = $handler->extract(-as_upload => "uploaded");
print "File name was ", $file->{filename}, "\n";
print "File contents: \n";
print $file->{payload};
=head1 DESCRIPTION
This L<CGI::Untaint> handler receives a file from an upload field,
returning its filename and contents. This may be used as a base class
for validating that a file upload conforms to certain properties.
It's important that you use C<< CGI->param >> rather than C<< CGI->Vars >>
as the latter only returns the uploaded file's name and not its
contents.
=head1 SUBCLASSING
By default, the class does no taint checking, blindly untainting both
view all matches for this distribution
CGI-Upload
view release on metacpan or search on metacpan
use strict;
#use CGI;
#use CGI::Simple;
use Test::More tests => 2;
# this script shows how can one upload a file using CGI.pm as the back end.
# there is no need for CGI.pm in the client part of the test script.
$ENV{REQUEST_METHOD} = 'POST';
$ENV{CONTENT_LENGTH} = '217';
$ENV{CONTENT_TYPE} = 'multipart/form-data; boundary=----------9GN0yM260jGW3Pq48BILfC';
if ($ARGV[0] eq 5) {
$q = "CGI::Minimal";
}
upload($q);
}
open my $fhs, "<", "local.file" or die "Could not open local.file $!\n";
my $uploaded_content;
my $uploaded_size = read $fhs, $uploaded_content, 10000;
open my $fhc, "<", "local/plain.txt" or die "Cannot open local/plain.txt\n";
my $original_content;
my $original_size = read $fhc, $original_content, 10000;
is($uploaded_size, $original_size, "size is correct");
is($uploaded_content, $original_content, "Content is the same");
sub upload {
my $arg = shift;
my $q;
my $fh;
if ("CGI::Simple" eq $arg) {
$CGI::Simple::DISABLE_UPLOADS = 0;
}
$q = new $arg;
}
$fh = $q->upload('field');
my $buffer;
if (open my $localfh, ">", "local.file") {
view all matches for this distribution
CGI-UploadEasy
view release on metacpan or search on metacpan
UploadEasy.pm view on Meta::CPAN
our $VERSION = '1.00';
# $Id: UploadEasy.pm,v 1.8 2009/02/01 21:04:22 gunnarh Exp $
=head1 NAME
CGI::UploadEasy - Facilitate file uploads
=head1 SYNOPSIS
use CGI::UploadEasy;
my $ue = CGI::UploadEasy->new(-uploaddir => '/path/to/upload/dir');
my $cgi = $ue->cgiobject;
my $info = $ue->fileinfo;
=head1 DESCRIPTION
C<CGI::UploadEasy> is a wrapper around, and relies heavily on, L<CGI.pm|CGI>. Its
purpose is to provide a simple interface to the upload functionality of C<CGI.pm>.
At creation of the C<CGI::UploadEasy> object, the module saves one or more files
from a file upload request in the upload directory, and information about uploaded
files is made available via the B<fileinfo()> method. C<CGI::UploadEasy> performs
a number of tests, which limit the risk that you encounter difficulties when
developing a file upload application.
=head2 Methods
=cut
UploadEasy.pm view on Meta::CPAN
if ( my $status = $self->{cgi}->cgi_error ) {
_error($self, $status, "Post too large: Maxsize $self->{maxsize} KiB exceeded.");
}
if ( $ENV{REQUEST_METHOD} eq 'POST' and $ENV{CONTENT_TYPE} !~ /^multipart\/form-data\b/i ) {
_error($self, '400 Bad Request', 'The content-type at file uploads shall be '
. "'multipart/form-data'.<br />\nMake sure that the 'FORM' tag includes the "
. 'attribute: enctype="multipart/form-data"');
}
$self->{files} = _upload($self);
bless $self, $class;
}
=over 4
=item B<my $ue = CGI::UploadEasy-E<gt>new( -uploaddir =E<gt> $dir [ , -maxsize =E<gt> $kibibytes, ... ] )>
The B<new()> constructor takes hash style arguments. The following arguments are
recognized:
=over 4
=item B<-uploaddir>
Specifying the upload directory is mandatory.
=item B<-tempdir>
To control which directory will be used for temporary files, set the -tempdir
argument.
UploadEasy.pm view on Meta::CPAN
=over 4
=item B<$ue-E<gt>fileinfo>
Returns a reference to a 'hash of hashes' with info about uploaded files. The info
may be of use for a result page and/or an email notification, and it lets you use
e.g. MIME type and file size as criteria for how to further process the files.
=back
UploadEasy.pm view on Meta::CPAN
=over 4
=item B<$ue-E<gt>otherparam>
The B<otherparam()> method returns a list of parameter names besides the names
of the file select controls that were used for file uploads. To access the values,
use L<CGI.pm|CGI>'s B<param()> method.
=back
=cut
sub _argscheck {
my %args;
my %names = (
-uploaddir => 'uploaddir',
-tempdir => 'tempdir',
-maxsize => 'maxsize',
);
local $Carp::CarpLevel = 2;
UploadEasy.pm view on Meta::CPAN
while ( my $arg = shift ) {
my $name = lc $arg;
$names{$name} or croak "Unknown argument: '$arg'";
$args{ $names{$name} } = shift;
}
$args{uploaddir} or croak "The compulsory argument '-uploaddir' is missing";
for my $dir ( @args{ grep exists $args{$_}, qw/uploaddir tempdir/ } ) {
-d $dir or croak "Can't find any directory '$dir'";
-r $dir and -w _ and -x _ or croak 'The user this script runs as ',
"does not have write access to '$dir'";
}
$args{maxsize} and $args{maxsize} !~ /^-?\d+$/
and croak "The '-maxsize' argument shall be an integer";
%args;
}
sub _upload {
my $self = shift;
my $cgi = $self->{cgi};
my %files;
for my $TEMP ( map $cgi->upload($_), $cgi->param ) {
( my $name = $TEMP ) =~ s#.*[\]:\\/]##;
$name =~ tr/ /_/ unless $^O eq 'MSWin32';
$name =~ tr/-+@a-zA-Z0-9. /_/cs;
($name) = $name =~ /^([-+@\w. ]+)$/;
my $path = File::Spec->catfile( $self->{uploaddir}, $name );
# don't overwrite file with same name
my $i = 2;
while (1) {
last unless -e $path;
$name =~ s/([^.]+?)(?:_\d+)?(\.|$)/$1_$i$2/;
$path = File::Spec->catfile( $self->{uploaddir}, $name );
$i++;
}
my ($cntrname) = $cgi->uploadInfo($TEMP)->{'Content-Disposition'} =~ /\bname="([^"]+)"/;
$files{$name} = {
ctrlname => $cntrname,
mimetype => $cgi->uploadInfo($TEMP)->{'Content-Type'},
};
open my $OUT, '>', $path or die "Couldn't open file: $!";
if ( $files{$name}{mimetype} =~ /^text\b/ ) {
binmode $TEMP, ':crlf';
UploadEasy.pm view on Meta::CPAN
__END__
=head1 EXAMPLE
This script handles a file upload request by saving a number of files in the
upload directory and printing the related info:
#!/usr/bin/perl -T
use strict;
use warnings;
use CGI::UploadEasy;
use Data::Dumper;
my $ue = CGI::UploadEasy->new(-uploaddir => '/path/to/upload/dir');
my $info = $ue->fileinfo;
my $cgi = $ue->cgiobject;
print $cgi->header('text/plain');
print Dumper $info;
=head1 CAVEATS
Since C<CGI::UploadEasy> is meant for file uploads, it requires that the request
data is C<multipart/form-data> encoded. An C<application/x-www-form-urlencoded>
POST request will cause a fatal error.
No C<CGI> object may be created before the C<CGI::UploadEasy> object has been
created, or else the upload will fail. Likewise, if you import method names from
C<CGI.pm>, be careful not to call any C<CGI> functions before the creation of the
C<CGI::UploadEasy> object.
=head1 AUTHOR, COPYRIGHT AND LICENSE
view all matches for this distribution( run in 1.478 second using v1.01-cache-2.11-cpan-b16cb0d3907 )