view release on metacpan or search on metacpan
use Module::Build;
my $build = Module::Build->new
(
module_name => 'CGI::Upload',
license => 'perl',
dist_author => 'Rob Casey <rob.casey@bluebottle.com>',
dist_abstract => 'CGI class for handling browser file uploads',
create_makefile_pl => 'traditional',
create_readme => 1,
requires => {
'perl' => 5.006,
'CGI' => 2.47,
'File::MMagic' => 1.16,
'HTTP::BrowserDetect' => 0.97,
'Test::More' => 0,
'Carp' => 0,
},
1.05 Sun Nov 24 22:15:00 2002
- included DESTROY subroutine; rob@cowsnet.com.au
- updated module tests; rob@cowsnet.com.au
1.06 Mon May 31 20:58:15 GMT+2 2004
- adding some tests
- Apply patches for bugs reported in RT #1854 and #5823
- Explicit undef as return value was replaced by return with nothing.
This might cause bad code such as this
@a = $upload->file_handle;
that relies on undef in list context to fail.
- (blame me: gabor@pti.co.il)
1.07 Tue Jun 8 12:55:39 GMT+2 2004
- Add CGI.pm 2.47 as requirement
so we can use the more correct "upload" method for getting the file handle.
- Add (experiamental) support for CGI::Simple and theoretically to other CGI-like modules.
CGI.pm and CGI::Simple are actually tested.
1.08 Tue Jun 8 21:07:44 GMT+2 2004
- skip CGI::Simple tests if CGI::Simple is not installed on the system
- Add to TODO list
1.09 Tue Jun 15 09:02:35 GMT+2 2004
- fixing binmode in Test.pm to work on Windows as well
- Updating the e-mail of Rob so he can get SPAM on his new address too.
lib/CGI/Upload.pm
local/plain.txt
local/plain.txt_multi
MANIFEST This list of files
README.md
t/critic.t
t/lib/CGI/Upload/Test.pm
t/module.t
t/pod-coverage.t
t/pod.t
t/upload.t
t/upload_any.t
t/upload_cgi.t
t/upload_cgi_instance.t
t/upload_cgi_simple.t
t/upload_cgi_simple_instance.t
t/upload_nonexistant.t
t/upload_windows.t
Makefile.PL
README
META.yml
META.json
{
"abstract" : "CGI class for handling browser file uploads",
"author" : [
"Rob Casey <rob.casey@bluebottle.com>"
],
"dynamic_config" : 1,
"generated_by" : "Module::Build version 0.4234",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
---
abstract: 'CGI class for handling browser file uploads'
author:
- 'Rob Casey <rob.casey@bluebottle.com>'
build_requires: {}
configure_requires:
Module::Build: '0.42'
dynamic_config: 1
generated_by: 'Module::Build version 0.4234, CPAN::Meta::Converter version 2.150010'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
NAME
CGI::Upload - CGI class for handling browser file uploads
SYNOPSIS
use CGI::Upload;
my $upload = CGI::Upload->new;
my $file_name = $upload->file_name('field');
my $file_type = $upload->file_type('field');
$upload->mime_magic('/path/to/mime.types');
my $mime_type = $upload->mime_type('field');
my $file_handle = $upload->file_handle('field');
DESCRIPTION
This module has been written to provide a simple and secure manner by
which to handle files uploaded in multipart/form-data requests through a
web browser. The primary advantage which this module offers over
existing modules is the single interface which it provides for the most
often required information regarding files uploaded in this manner.
This module builds upon primarily the CGI and File::MMagic modules and
offers some tidy and succinct methods for the handling of files uploaded
via multipart/form-data requests.
METHODS
The following methods are available through this module for use in CGI
scripts and can be exported into the calling namespace upon request.
new This object constructor method creates and returns a new CGI::Upload
object. In previously versions of CGI::Upload, a mandatory argument
of the CGI object to be used was required. This is no longer
necessary due to the singleton nature of CGI objects.
As an experiment, you can now use any kind of CGI.pm like module.
The requirements are that it has to support the ->param method and
the ->upload method returning a file handle. You can use this
feature in two ways, either providing the name of the module or an
already existing object. In the former case, CGI::Upload will try to
*require* the correct module and will *croak* if cannot load that
module. It has been tested with CGI.pm and CGI::Simple.
We tested it with CGI::Simple 0.075.
It is known to break with version 0.071 of CGI::Simple so we issue
our own die in such case.
use CGI::Simple;
$CGI::Simple::DISABLE_UPLOADS = 0; # you have to set this before creating the instance
my $q = CGI::Simple->new;
CGI::Upload->new({ query => $q});
query
Returns the CGI object used within the CGI::Upload class.
file_handle('field')
This method returns the file handle to the temporary file containing
the file uploaded through the form input field named 'field'. This
temporary file is generated using the new_tmpfile method of IO::File
and is anonymous in nature, where possible.
file_name('field')
This method returns the file name of the file uploaded through the
form input field named 'field' - This file name does not reflect the
local temporary filename of the uploaded file, but that for the file
supplied by the client web browser.
file_type('field')
This method returns the file type of the file uploaded as specified
by the filename extension - Please note that this does not
necessarily reflect the nature of the file uploaded, but allows CGI
scripts to perform cursory validation of the file type of the
uploaded file.
mime_magic('/path/to/mime.types')
This method sets and/or returns the external magic mime types file
to be used for the identification of files via the mime_type method.
By default, MIME identification is based upon internal mime types
defined within the File::MMagic module.
See File::MMagic for further details.
mime_type('field')
This method returns the MIME type of the file uploaded through the
form input field named 'field' as determined by file magic numbers.
This is the best means by which to validate the nature of the
uploaded file.
See File::MMagic for further details.
BUGS
Please report bugs on RT:
<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CGI-Upload>
TODO
Explain why there is no 100% tests coverage...
Give inteligent error message when user forgets to add
enctype="multipart/form-data" in the upload form.
Add better MIME magic support (see request on RT)
Test if multiple file uploads are supported and fix this if they are
not.
Apache::Request support
CGI::Minimal support
Example code from Mark Stosberg (CGI::Uploader):
if ($q->isa('CGI::Simple') ) {
$fh = $q->upload($filename);
$mt = $q->upload_info($filename, 'mime' );
if (!$fh && $q->cgi_error) {
warn $q->cgi_error && return undef;
}
}
elsif ( $q->isa('Apache::Request') ) {
my $upload = $q->upload($file_field);
$fh = $upload->fh;
$mt = $upload->type;
}
# default to CGI.pm behavior
else {
$fh = $q->upload($file_field);
$mt = $q->uploadInfo($fh)->{'Content-Type'} if $q->uploadInfo($fh);
if (!$fh && $q->cgi_error) {
warn $q->cgi_error && return undef;
}
}
SEE ALSO
CGI, File::MMagic, HTTP::File
COPYRIGHT
#!/usr/bin/perl -w
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';
$ENV{HTTP_USER_AGENT} = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312";
unlink "local.file";
hmm();
#unlink "local.file";
if ($ARGV[0] eq 4) {
require CGI::Simple;
$CGI::Simple::DISABLE_UPLOADS = 0;
$q = new CGI::Simple;
}
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;
#warn "$arg\n";
if (ref $arg) { # passed an object
$q = $arg;
} else {
(my $file = $arg) =~ s{::}{/}g;
$file .= ".pm";
require $file;
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") {
while (read $fh, $buffer, 100) {
print $localfh $buffer;
}
} else {
die "could not open local.file $!";
lib/CGI/Upload.pm view on Meta::CPAN
unless ( grep { $property eq $_ } @properties ) {
croak( __PACKAGE__, '->AUTOLOAD : Unsupported object method within module - ', $property );
}
# Return undef if the requested parameter does not exist within
# CGI object
my $cgi = $self->query;
return unless defined $cgi->param( $param );
# The determination of all information about the uploaded file is
# performed by a private subroutine called _handle_file - This subroutine
# returns a hash of all information determined about the uploaded file
# which is be cached for subsequent requests.
$self->{'_CACHE'}->{$param} = $self->_handle_file( $param ) unless exists $self->{'_CACHE'};
# Return the requested property of the uploaded file
return $self->{'_CACHE'}->{$param}->{$property};
}
sub DESTROY {}
sub _handle_file {
my ( $self, $param ) = @_;
my $cgi = $self->query;
# Determine and set the appropriate file system parsing routines for the
# uploaded path name based upon the HTTP client header information.
my $client_os = $^O;
my $browser = HTTP::BrowserDetect->new;
$client_os = 'MSWin32' if $browser->windows;
$client_os = 'MacOS' if $browser->mac;
fileparse_set_fstype($client_os);
my @file = fileparse( scalar($cgi->param( $param )), '\.[^.]*' );
# Return an undefined value if the file name cannot be parsed from the
# file field form parameter.
return unless $file[0];
# Determine whether binary mode is required in the handling of uploaded
# files -
# Binary mode is deemed to be required when we (the server) are running one one
# of these platforms: for Windows, OS/2 and VMS
my $binmode = $^O =~ /OS2|VMS|Win|DOS|Cygwin/i;
# Pass uploaded file into temporary file handle - This is somewhat
# redundant given the temporary file generation within CGI.pm, however is
# included to reduce dependence upon the CGI.pm module.
my $buffer;
my $fh = IO::File->new_tmpfile;
binmode( $fh ) if $binmode;
# it seems that in CGI::Simple for every call to ->upload it somehow resets
# the file handle. or I don't really know what is the problem with this code:
# while ( read( $cgi->upload( $param ) , $buffer, 1024 ) ) {
my $ourfh = $cgi->upload( $param );
while ( read( $ourfh , $buffer, 1024 ) ) {
$fh->write( $buffer, length( $buffer ) );
}
# Hold temporary file open, move file pointer to start - As the temporary
# file handle returned by the IO::File::new_tmpfile method is only
# accessible via this handle, the file handle must be held open for all
# operations.
$fh->seek( 0, 0 );
# Retrieve the MIME magic file, if this has been defined, and construct
# the File::MMagic object for the identification of the MIME type of the
# uploaded file.
my $mime_magic = $self->mime_magic;
my $magic = length $mime_magic ? File::MMagic->new( $mime_magic ) : File::MMagic->new;
my $properties = {
'file_handle' => $fh,
'file_name' => $file[0] . $file[2],
'file_type' => lc substr( $file[2], 1 ),
'mime_type' => $magic->checktype_filehandle($fh)
};
lib/CGI/Upload.pm view on Meta::CPAN
1;
__END__
=pod
=head1 NAME
CGI::Upload - CGI class for handling browser file uploads
=head1 SYNOPSIS
use CGI::Upload;
my $upload = CGI::Upload->new;
my $file_name = $upload->file_name('field');
my $file_type = $upload->file_type('field');
$upload->mime_magic('/path/to/mime.types');
my $mime_type = $upload->mime_type('field');
my $file_handle = $upload->file_handle('field');
=head1 DESCRIPTION
This module has been written to provide a simple and secure manner by which to
handle files uploaded in multipart/form-data requests through a web browser.
The primary advantage which this module offers over existing modules is the
single interface which it provides for the most often required information
regarding files uploaded in this manner.
This module builds upon primarily the B<CGI> and B<File::MMagic> modules and
offers some tidy and succinct methods for the handling of files uploaded via
multipart/form-data requests.
=head1 METHODS
The following methods are available through this module for use in CGI scripts
and can be exported into the calling namespace upon request.
=over 4
=item B<new>
This object constructor method creates and returns a new B<CGI::Upload> object.
In previously versions of B<CGI::Upload>, a mandatory argument of the B<CGI>
object to be used was required. This is no longer necessary due to the
singleton nature of B<CGI> objects.
As an experiment, you can now use any kind of CGI.pm like module. The requirements
are that it has to support the ->param method and the ->upload method returning a
file handle. You can use this feature in two ways, either providing the name of
the module or an already existing object. In the former case, CGI::Upload will try
to I<require> the correct module and will I<croak> if cannot load that module.
It has been tested with CGI.pm and CGI::Simple.
We tested it with CGI::Simple 0.075.
It is known to break with version 0.071 of CGI::Simple so we issue our own die in such case.
Examples:
lib/CGI/Upload.pm view on Meta::CPAN
my $q = CGI::Simple->new;
CGI::Upload->new({ query => $q});
=item B<query>
Returns the B<CGI> object used within the B<CGI::Upload> class.
=item B<file_handle('field')>
This method returns the file handle to the temporary file containing the file
uploaded through the form input field named 'field'. This temporary file is
generated using the B<new_tmpfile> method of B<IO::File> and is anonymous in
nature, where possible.
=item B<file_name('field')>
This method returns the file name of the file uploaded through the form input
field named 'field' - This file name does not reflect the local temporary
filename of the uploaded file, but that for the file supplied by the client web
browser.
=item B<file_type('field')>
This method returns the file type of the file uploaded as specified by the
filename extension - Please note that this does not necessarily reflect the
nature of the file uploaded, but allows CGI scripts to perform cursory
validation of the file type of the uploaded file.
=item B<mime_magic('/path/to/mime.types')>
This method sets and/or returns the external magic mime types file to be used
for the identification of files via the B<mime_type> method. By default, MIME
identification is based upon internal mime types defined within the
B<File::MMagic> module.
See L<File::MMagic> for further details.
=item B<mime_type('field')>
This method returns the MIME type of the file uploaded through the form input
field named 'field' as determined by file magic numbers. This is the best
means by which to validate the nature of the uploaded file.
See L<File::MMagic> for further details.
=back
=head1 BUGS
Please report bugs on RT: L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CGI-Upload>
=head1 TODO
Explain why there is no 100% tests coverage...
Give inteligent error message when user forgets to add enctype="multipart/form-data" in the upload form.
Add better MIME magic support (see request on RT)
Test if multiple file uploads are supported and fix this if they are not.
Apache::Request support
CGI::Minimal support
Example code from Mark Stosberg (CGI::Uploader):
if ($q->isa('CGI::Simple') ) {
$fh = $q->upload($filename);
$mt = $q->upload_info($filename, 'mime' );
if (!$fh && $q->cgi_error) {
warn $q->cgi_error && return undef;
}
}
elsif ( $q->isa('Apache::Request') ) {
my $upload = $q->upload($file_field);
$fh = $upload->fh;
$mt = $upload->type;
}
# default to CGI.pm behavior
else {
$fh = $q->upload($file_field);
$mt = $q->uploadInfo($fh)->{'Content-Type'} if $q->uploadInfo($fh);
if (!$fh && $q->cgi_error) {
warn $q->cgi_error && return undef;
}
}
=head1 SEE ALSO
L<CGI>, L<File::MMagic>, L<HTTP::File>
local/plain.txt view on Meta::CPAN
This is a plain text file we try to upload.
local/plain.txt_multi view on Meta::CPAN
------------9GN0yM260jGW3Pq48BILfC
Content-Disposition: form-data; name="field"; filename="plain.txt"
Content-Type: text/plain
This is a plain text file we try to upload.
------------9GN0yM260jGW3Pq48BILfC--
t/lib/CGI/Upload/Test.pm view on Meta::CPAN
package CGI::Upload::Test;
use strict;
use warnings;
use base 'Exporter';
## no critic (ProhibitAutomaticExportation);
our @EXPORT = qw(&upload_file &is_installed);
use Test::More;
use File::Spec::Functions qw(catfile);
# subroutine to upload any file (and prepare the multi-part version of it on the fly).
# For some reason you cannot run this function twice !?? What bug is this ?
# using local/plain.txt
use CGI::Upload;
sub upload_file {
my $original_file = shift;
my $args = shift || {};
my $long_filename_on_client = $args->{long_filename_on_client} || $original_file;
my $short_filename_on_client = $args->{short_filename_on_client} || $original_file;
my $binmode = $^O =~ /OS2|VMS|Win|DOS|Cygwin/i;
#### Prepare environment that looks like a CGI environment
my $boundary = "----------9GN0yM260jGW3Pq48BILfC";
t/lib/CGI/Upload/Test.pm view on Meta::CPAN
$original .= qq(Content-Disposition: form-data; name="field"; filename="$long_filename_on_client"\r\n);
$original .= qq(Content-Type: text/plain\r\n\r\n);
$original .= qq($original_content\r\n);
$original .= qq(--$boundary--\r\n);
local $ENV{REQUEST_METHOD} = "POST";
local $ENV{CONTENT_LENGTH} = length $original;
local $ENV{CONTENT_TYPE} = qq(multipart/form-data; boundary=$boundary);
my $u;
my $uploaded_content;
my $uploaded_size;
{
local *STDIN;
#open STDIN, "<", \$original;
# As I can see CGI::Simple cannot work with in-memory file handle
# (is it due to using sysread ?) so we have to save the content in
# a temporary file.
open my $fh, '>', 'tmpfile' or die "Cannot create temporary file: $!";
binmode $fh if $binmode;
print $fh $original;
t/lib/CGI/Upload/Test.pm view on Meta::CPAN
$module = CGI->new;
}
}
if ($module) {
$u = CGI::Upload->new({query => $module});
} else {
$u = CGI::Upload->new();
}
my $remote = $u->file_handle('field');
$uploaded_size = read $remote, $uploaded_content, 10000;
unlink "tmpfile";
}
is($u->file_name("field"), $short_filename_on_client, "filename '$short_filename_on_client' is correct");
is($uploaded_size, $original_size, "size is correct");
is($uploaded_content, $original_content, "Content is the same");
# we might not need to test the following failors in every call, but on the other hand, why not ?
eval {
$u->invalid_call()
};
like($@, qr{CGI::Upload->AUTOLOAD : Unsupported object method within module - invalid_call}, "Invalid call trapped");
ok(not(defined $u->file_name("other_field")), "returns undef");
return;
}
# Comment:
# the CGI::Upload call under -w causes a warning in the CGI module that is reported as one of these:
# Use of uninitialized value in pattern match (m//) at (eval 8) line 4
# this hapens if the HTTP_USER_AGENT is not defined
# On the other hand HTTP::BrowserDetect complains heavily if the HTTP_USER_AGENT is not something
# it expects. e.g. this one: $ENV{HTTP_USER_AGENT} = "Linux";
# This is not very related to CGI::Upload but well.
# If I copy-paste the whole section of the upload, the second section does not
# work correctly. Is this a bug or a user error ?
#open(my $in, '<', 't/upload_post_text.txt') or die 'missing test file';
use lib 'lib';
use CGI::Upload;
use Test::More tests => 4;
{
local $ENV{REQUEST_METHOD} = 'POST';
local $ENV{CONTENT_LENGTH} = '217';
#local $ENV{QUERY_STRING} = '';
local $ENV{CONTENT_TYPE} = 'multipart/form-data; boundary=----------9GN0yM260jGW3Pq48BILfC';
$ENV{HTTP_USER_AGENT} = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312";
my $u;
my $uploaded_content;
my $uploaded_size;
{
local *STDIN;
## no critic (ProhibitBarewordFileHandles)
open(STDIN, '<', 'local/plain.txt_multi')
or die "missing test file 'local/plain.txt_multi'\n";
binmode(STDIN);
$u = CGI::Upload->new();
#SKIP: {
# skip "fix invalid call", 1;
ok(not(defined $u->file_name("other_field")), "returns undef");
#}
my $remote = $u->file_handle('field');
$uploaded_size = read $remote, $uploaded_content, 10000;
}
is($u->file_name("field"), "plain.txt", "filename is correct");
open my $fh, "<", "local/plain.txt" or die "Cannot open local/plain.txt\n";
my $original_content;
my $original_size = read $fh, $original_content, 10000;
is($uploaded_size, $original_size, "size is correct");
is($uploaded_content, $original_content, "Content is the same");
}
t/upload_any.t view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
# subroutine to upload any file (and prepare the multi-part version of it on the fly).
# For some reason you cannot run this function twice !?? What bug is this ?
# using local/plain.txt
use lib qw(lib t/lib);
use CGI::Upload;
use CGI::Upload::Test;
use Test::More tests => 6*1;
#upload_file("plain.txt");
$ENV{HTTP_USER_AGENT} = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312";
upload_file("plain.txt", {
long_filename_on_client => '/tmp/plain.txt',
short_filename_on_client => 'plain.txt',
});
ok($INC{"CGI.pm"}, "CGI.pm was loaded");
#upload_file("plain.txt");
t/upload_cgi.t view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
# subroutine to upload any file (and prepare the multi-part version of it on the fly).
# For some reason you cannot run this function twice !?? What bug is this ?
# using local/plain.txt
use lib qw(lib t/lib);
use CGI::Upload;
use CGI::Upload::Test;
use Test::More tests => 7;
$ENV{HTTP_USER_AGENT} = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312";
upload_file(
"plain.txt",
{
long_filename_on_client => '/tmp/plain.txt',
short_filename_on_client => 'plain.txt',
module => "CGI",
instance => 0,
},
);
ok(not(defined $INC{"CGI/Simple.pm"}), "CGI::Simple was not loaded");
t/upload_cgi_instance.t view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
# subroutine to upload any file (and prepare the multi-part version of it on the fly).
# For some reason you cannot run this function twice !?? What bug is this ?
# using local/plain.txt
use lib qw(lib t/lib);
use CGI::Upload;
use CGI::Upload::Test;
use Test::More tests => 7;
$ENV{HTTP_USER_AGENT} = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312";
upload_file(
"plain.txt",
{
long_filename_on_client => '/tmp/plain.txt',
short_filename_on_client => 'plain.txt',
module => "CGI",
instance => 1,
},
);
ok(not(defined $INC{"CGI/Simple.pm"}), "CGI::Simple was not loaded");
t/upload_cgi_simple.t view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
# subroutine to upload any file (and prepare the multi-part version of it on the fly).
# For some reason you cannot run this function twice !?? What bug is this ?
# using local/plain.txt
use lib qw(lib t/lib);
use CGI::Upload;
use CGI::Upload::Test;
use Test::More tests => 7;
SKIP: {
skip "CGI::Simple needed for these tests", 7 unless is_installed("CGI::Simple");
$ENV{HTTP_USER_AGENT} = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312";
eval {
upload_file(
"plain.txt",
{
long_filename_on_client => '/tmp/plain.txt',
short_filename_on_client => 'plain.txt',
module => "CGI::Simple",
instance => 0,
},
);
};
if ($@ and $@ =~ /^CGI::Simple must be at least version 0.075$/) {
t/upload_cgi_simple_instance.t view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
# subroutine to upload any file (and prepare the multi-part version of it on the fly).
# For some reason you cannot run this function twice !?? What bug is this ?
# using local/plain.txt
use lib qw(lib t/lib);
use CGI::Upload;
use CGI::Upload::Test;
use Test::More tests => 7;
SKIP: {
skip "CGI::Simple needed for these tests", 7 unless is_installed("CGI::Simple");
$ENV{HTTP_USER_AGENT} = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312";
eval {
upload_file(
"plain.txt",
{
long_filename_on_client => '/tmp/plain.txt',
short_filename_on_client => 'plain.txt',
module => "CGI::Simple",
instance => 1,
},
);
};
if ($@ and $@ =~ /^CGI::Simple must be at least version 0.075$/) {
t/upload_nonexistant.t view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
# subroutine to upload any file (and prepare the multi-part version of it on the fly).
# For some reason you cannot run this function twice !?? What bug is this ?
# using local/plain.txt
use lib qw(lib t/lib);
use CGI::Upload;
use CGI::Upload::Test;
use Test::More tests => 3;
$ENV{HTTP_USER_AGENT} = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312";
eval {
upload_file(
"plain.txt",
{
long_filename_on_client => '/tmp/plain.txt',
short_filename_on_client => 'plain.txt',
module => "Bad::ModuleName",
instance => 0,
},
);
};
like($@, qr{Can't locate Bad/ModuleName.pm in \@INC}, 'Error was received');
t/upload_windows.t view on Meta::CPAN
use lib qw(lib t/lib);
use CGI::Upload;
use CGI::Upload::Test;
use Test::More tests => 5*1;
#$ENV{HTTP_USER_AGENT} = "Mozilla/4.7 [fr] (Win95; U)";
$ENV{HTTP_USER_AGENT} = 'Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)';
#,'4.01','MSIE','Win95',qw(ie ie4 ie4up windows win32 win95)
upload_file("plain.txt", {
long_filename_on_client => 'c:\0123.txt',
short_filename_on_client => '0123.txt',
});