Result:
found more than 723 distributions - search limited to the first 2001 files matching your query ( run in 2.871 )


CGI-Easy

 view release on metacpan or  search on metacpan

lib/CGI/Easy.pm  view on Meta::CPAN

    my $url = "$r->{scheme}://$r->{host}:$r->{port}$r->{path}";
    my $param_name  = $r->{GET}{name};
    my @param_color = @{ $r->{GET}{'color[]'} };
    my $cookie_some = $r->{cookie}{some};

    # -- file upload
    my $avatar_image    = $r->{POST}{avatar};
    my $avatar_filename = $r->{filename}{avatar};
    my $avatar_mimetype = $r->{mimetype}{avatar};

    # -- easy way to identify visitors and get data stored in cookies

 view all matches for this distribution


CGI-ExtDirect

 view release on metacpan or  search on metacpan

lib/CGI/ExtDirect.pm  view on Meta::CPAN

               :                 undef
               ;
    };

    # If any files are attached, extUpload will contain 'true'
    my $has_uploads = $cgi->param('extUpload') eq 'true';

    # Here file uploads data is stored
    my @_uploads = ();

    # This is to suppress a really annoying warning in CGI.pm 4.08+.
    # I am perfectly aware of what the list context is and how to
    # use it, thank you very much. :/
    local $CGI::LIST_CONTEXT_WARN = 0;

lib/CGI/ExtDirect.pm  view on Meta::CPAN

        $keyword{ $param } = @values == 0 ? undef
                           : @values == 1 ? $values[0]
                           :                [ @values ]
                           ;

        # Try to see if $param is a field with associated file upload
        # Skip the standard ones first, of course
        next PARAM if $STANDARD_KEYWORD{ $param } || !$has_uploads;

        # Look for file uploads in this field
        my @field_uploads = $self->_parse_uploads($cgi, $param);

        # Found some, add them to the general stash and kill the field
        if ( @field_uploads ) {
            push @_uploads, @field_uploads;
            delete $keyword{ $param };
        };
    };

    # Metadata is JSON encoded; decode_metadata lives by side effects!

lib/CGI/ExtDirect.pm  view on Meta::CPAN


    # Fix up the TID so that it comes as a number (JavaScript is picky)
    $keyword{ extTID } += 0 if exists $keyword{ extTID };

    # Now add files to hash, if any
    $keyword{ '_uploads' } = \@_uploads if @_uploads;

    return \%keyword;
}

### PRIVATE INSTANCE METHOD ###
#
# Parses CGI form input field looking for file uploads
#

sub _parse_uploads {
    my ($self, $cgi, $param) = @_;

    # CGI returns "lightweight file handles", or undef
    my @file_handles = $cgi->upload($param);

    # Empty list means no uploads for this field
    return unless grep { defined $_ } @file_handles;

    # Despite what CGI documentation says, the values returned
    # as "file names" are actually some kind of key handles
    my @file_keys = $cgi->param($param);

    # Here file uploads get collected
    my @uploads = ();

    # Collect the info we need to repackage it in a consistent way
    FILE:
    for my $key ( @file_keys ) {
        # First take a closer look at this "blah-blah handle"
        my $file_handle = shift @file_handles;

        # undef would mean there was an upload error (timeout perhaps)
        # Following HTTP POST logic, when one upload breaks, that
        # would mean all subsequent uploads in this POST are also
        # broken.
        # We can't recover from that so just stop trying.
        last FILE unless defined $file_handle;

        # In CGI.pm < 3.41, "lightweight handle" object doesn't support
        # returning IO::Handle so we do it manually to avoid problems
        my $io_handle = IO::Handle->new_from_fd(fileno $file_handle, '<');

        # We also need a lot of info about the file (if provided)
        my $upload_info = $cgi->uploadInfo($key);
        my $temp_file   = $cgi->tmpFileName($key);
        my $file_type   = $upload_info->{'Content-Type'};
        my $file_name   = $self->_get_file_name($upload_info);
        my $file_size   = $self->_get_file_size($io_handle);
        my $base_name   = basename($file_name);

        # Now instead of a "blah-blah handle" we have a normalized hashref
        push @uploads, {
            type     => $file_type,
            size     => $file_size,
            path     => $temp_file,
            handle   => $io_handle,
            basename => $base_name,
            filename => $file_name,
        };
    };

    return @uploads;
}

### PRIVATE INSTANCE METHOD ###
#
# Tries hard to extract file name from multipart form guts
#

sub _get_file_name {
    my ($self, $upload_info) = @_;

    # Pluck file name from Content-Disposition string
    my ($file_name)
        = $upload_info->{'Content-Disposition'} =~ /filename="(.*?)"/;

    # URL unescape it
    $file_name =~ s/%([\dA-Fa-f]{2})/pack("C", hex $1)/eg;

    return $file_name;

 view all matches for this distribution


CGI-Fast

 view release on metacpan or  search on metacpan

lib/CGI/Fast.pm  view on Meta::CPAN

		#
		# the interface to the ->new method is unfortunately somewhat
		# overloaded as it can be passed:
		#
		#         nothing
		#         an upload hook, "something", 0
		#         an initializer, an upload hook, "something", 0
		#
		# these then get passed through to the SUPER class (CGI.pm) that
		# also has a constructor that can take various order of args
		#
        my ($self, @args) = @_;

lib/CGI/Fast.pm  view on Meta::CPAN

    AddType application/x-httpd-fcgi .fcgi

FastCGI scripts must end in the extension .fcgi.  For each script you
install, you must add something like the following to srm.conf:

    FastCgiServer /usr/etc/httpd/fcgi-bin/file_upload.fcgi -processes 2

This instructs Apache to launch two copies of file_upload.fcgi at
startup time.

=head1 USING FASTCGI SCRIPTS AS CGI SCRIPTS

Any script that works correctly as a FastCGI script will also work

lib/CGI/Fast.pm  view on Meta::CPAN

FastCGI supports a TCP/IP transport mechanism which allows FastCGI scripts to run
external to the webserver, perhaps on a remote machine.  To configure the
webserver to connect to an external FastCGI server, you would add the following
to your srm.conf:

    FastCgiExternalServer /usr/etc/httpd/fcgi-bin/file_upload.fcgi -host sputnik:8888

Two environment variables affect how the C<CGI::Fast> object is created,
allowing C<CGI::Fast> to be used as an external FastCGI server. (See C<FCGI>
documentation for C<FCGI::OpenSocket> for more information.)

 view all matches for this distribution


CGI-FileManager

 view release on metacpan or  search on metacpan

lib/CGI/FileManager.pm  view on Meta::CPAN

# modes that can be accessed without a valid session
my @free_modes = qw(login login_process logout about redirect); 
my @restricted_modes = qw(
	list_dir 
	change_dir 
	upload_file 
	delete_file 
	create_directory 
	remove_directory
	rename_form
	rename

lib/CGI/FileManager.pm  view on Meta::CPAN

				# and in its parent (which is currenly shown in the browser) the file will be deleted
				# from the "current directory", I think the only solution is that the user supplies us
				# with full (virtual) path name for every action.
				# This seems to be easy regarding action on existing files as they are all done by clicking
				# on links and the links can contain.
				# Regardin upload/create dir and later create file we have to know where should the thing go
				# - what does the user think is the current working directory. For such operations we can
				# hide the workdir in a hidden field in the form.
				#
				# In either case we have to make sure the full virtual directory is something the user
				# has right to access.

lib/CGI/FileManager.pm  view on Meta::CPAN

	}
	return $self->_move($old, $new);
}


=head2 upload_file

Upload a file

=cut
sub upload_file {
	my $self = shift;
	my $q = $self->query;

	my $homedir = $self->session->param("homedir");
	my $workdir = $self->_untaint_path($q->param("workdir"));

	my $upload = CGI::Upload->new();
	my $file_name = $upload->file_name('filename');
	my $in = $upload->file_handle('filename');
	
	if (ref $in ne "IO::File") {
		warn "No file handle in upload ? '$file_name'";
		return $self->message("Hmm, strange. Please contact the administrator");
	}

	if ($file_name =~ /\.\./) {
		warn "two dots in upload file ? '$file_name'";
		return $self->message("Hmm, we don't recognize this. Please contact the administrator");
	}
	if ($file_name =~ /^([\w.-]+)$/) {
		$file_name = $1;
		if (open my $out, ">", File::Spec->catfile($homedir, $workdir,$file_name)) {

lib/CGI/FileManager.pm  view on Meta::CPAN

		} else {
			warn "Could not open local file: '$file_name'";
			return $self->message("Could not open local file. Please contact the administrator");
		}
	} else {
		warn "Invalid name for upload file ? '$file_name'";
		return $self->message("Hmm, we don't recognize this. Please contact the administrator");
	}

	$self->list_dir;
}

 view all matches for this distribution


CGI-FileUpload

 view release on metacpan or  search on metacpan

cgi/cgi-fileupload-manager.pl  view on Meta::CPAN

use Carp;
use Pod::Usage;

=head1 NAME

cgi-fileupload-manager.pl - a cgi script to display past and currently uploaded files, either for the curretn user or all (admin mode)

=cut

$|=1;		        #  flush immediately;

cgi/cgi-fileupload-manager.pl  view on Meta::CPAN

my $query=new CGI;

print $query->header;
#TODO css with border in table and bit better...
my $css;
if(open (FH, "<cgi-upload.css")){
  local $/;
  $css=<FH>;
  close FH;
}
print $query->start_html(-title => 'CGI::FileUpload manager',

cgi/cgi-fileupload-manager.pl  view on Meta::CPAN

EOT
# TODO get creation time + set it coherent with sort
my $id=CGI::FileUpload::idcookie(query=>$query)->{id};
foreach(@fus){
  next unless $isAdmin || ($_->from_id() eq $id);
  my $status=$_->upload_status();
  print "  <tr>\n";
  print "    <td>".$_->file_orig()."</td>\n";
  print "    <td>".(ctime((stat($_->file('.properties')))[9]))."</td>\n";
  print "    <td>$status</td>\n";
  print "    <td>".(($status eq 'completed')?(-s $_->file()):'n/a')."</td>\n";

 view all matches for this distribution


CGI-FormBuilder-Mail-FormatMultiPart

 view release on metacpan or  search on metacpan

lib/CGI/FormBuilder/Mail/FormatMultiPart.pm  view on Meta::CPAN

                Filename    => $form->field($_),
                Id          => $_,
                Disposition => 'attachment',
              } 
            }
            grep { $fbflds->{$_}->value }   # only files actually uploaded
            $self->_file_field_names()
    );
}

sub _data_form {

lib/CGI/FormBuilder/Mail/FormatMultiPart.pm  view on Meta::CPAN

If HTML, can pass a stylesheet that is printed in-line, as well as
arguments to HTML::QuickTable.  ('header' is ignored.)  The default
style class is 'fb_mail' for all elements.  You can use a partial CSS spec
to override this class's styles; defaults will otherwise still apply.

Will attach all file uploads as multipart MIME attachments.
The file names are listed in the form data table.

If it cannot be used, it will puke a warning message and die.

=head1 INSTALLATION

 view all matches for this distribution


CGI-FormBuilder

 view release on metacpan or  search on metacpan

lib/CGI/FormBuilder.pod  view on Meta::CPAN

=head2 I can't get "validate" to accept my regular expressions!

You're probably not specifying them within single quotes. See the
section on C<validate> above.

=head2 Can FormBuilder handle file uploads?

It sure can, and it's really easy too. Just change the C<enctype>
as an option to C<new()>:

    use CGI::FormBuilder;

lib/CGI/FormBuilder.pod  view on Meta::CPAN

        print $form->confirm(header => 1);
    } else {
        print $form->render(header => 1);
    }

In fact, that's a whole file upload program right there.

=head1 REFERENCES

This really doesn't belong here, but unfortunately many people are
confused by references in Perl. Don't be - they're not that tricky.

 view all matches for this distribution


CGI-FormMagick

 view release on metacpan or  search on metacpan

examples/fileupload.pl  view on Meta::CPAN

use lib "../lib/";
use CGI::FormMagick;
use Carp;

#
# Example of a file upload form. Note that you *must* include the
# <ENCTYPE>multipart/form-data</ENCTYPE> field in order to use 
# fields of type FILE. 
#

#

examples/fileupload.pl  view on Meta::CPAN

	print "The first 1024 bytes are:\n<pre>",$buf,"\n</pre>\n";
}

__END__
<FORM HEADER="" FOOTER="">
    <TITLE>File upload test</TITLE>

    <PAGE NAME="Upload" POST-EVENT="dump_file">
        <TITLE>Upload a file to the server</TITLE>
  
        <FIELD ID="filename" TYPE="FILE" VALIDATION="nonblank">

 view all matches for this distribution


CGI-Framework

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN


	- Implemented the ability to save session data in a mysql table instead of text files
	  through a new constructor parameter sessions_mysql_dbh.
	- Implemented a new method "remember" that is a shorthand for transferring values
	  from the just-submitted form to the session.
	- Changed default form enctype to "multipart/form-data" so that file-uploads can
	  be done.  This seems to have no side-effect other than enabling file uploads to
	  work.
	- Some documentation and synopsis bugfixes. - Thanks to Ron Savage <rons@deakin.edu.au>

0.03
	-  Added new methods: get_cgi_object, get_cgi_session_object, html_push, html_unshift

 view all matches for this distribution


CGI-Imagemap

 view release on metacpan or  search on metacpan

CHANGES  view on Meta::CPAN

Revision history for Perl extension CGI::Imagemap.

2.01  Sat Aug 16 10:54:24 EDT 2008
	Reupload due to PAUSE ignoring the corrupted (but usable) tarball

	Add ismap.cgi to MAINFEST

2.00  Tue Aug  5 00:00:42 UTC 2003
	Modernized by Jerrad Pierce; no more string eval, use strict.

 view all matches for this distribution


CGI-Info

 view release on metacpan or  search on metacpan

lib/CGI/Info.pm  view on Meta::CPAN

use namespace::clean;

# ---------------------------------------------------------------------------
# Module-level constants -- avoids magic numbers scattered through the code
# ---------------------------------------------------------------------------
Readonly my $MAX_UPLOAD_SIZE_DEFAULT => 512 * 1024;	# 512 KB default upload cap
Readonly my $CACHE_TTL_ROBOT         => '1 day';	# TTL for robot-detection cache entries
Readonly my $CACHE_TTL_SEARCH        => '1 day';	# TTL for search-engine cache entries

# Compiled once at module-load time: replaces the 29-element @crawler_lists array
# that was re-allocated on every is_robot() call.  Building the alternation with

lib/CGI/Info.pm  view on Meta::CPAN


=head2 new

Creates a CGI::Info object.

It takes four optional arguments: allow, logger, expect and upload_dir,
which are documented in the params() method.

It takes other optional parameters:

=over 4

lib/CGI/Info.pm  view on Meta::CPAN


On non-Windows system,
the class can be configured using environment variables starting with "CGI::Info::".
For example:

  export CGI::Info::max_upload_size=65536

It doesn't work on Windows because of the case-insensitive nature of that system.

If the configuration file has a section called C<CGI::Info>,
only that section,

lib/CGI/Info.pm  view on Meta::CPAN


An object that is used to cache IP lookups.
This cache object is an object that understands get() and set() messages,
such as a L<CHI> object.

=item * C<max_upload_size>

The maximum file size in bytes you can upload.
Use C<-1> for no limit.
The default is 512 KB (524288 bytes).

=back

lib/CGI/Info.pm  view on Meta::CPAN

    cache          => { type => 'object',   optional => 1 },
    carp_on_warn   => { type => 'boolean',  optional => 1 },
    config_dirs    => { type => 'arrayref', optional => 1 },
    config_file    => { type => 'string',   optional => 1 },
    logger         => { type => 'object',   optional => 1 },
    max_upload_size=> { type => 'integer',  optional => 1, min => -1 },
    upload_dir     => { type => 'string',   optional => 1 },
  }

=head4 OUTPUT

  { type => 'object', isa => 'CGI::Info' }

lib/CGI/Info.pm  view on Meta::CPAN

		Carp::croak("$class: expect has been deprecated, use allow instead");
	}

	# Return the blessed object with sensible defaults
	return bless {
		max_upload_size => $MAX_UPLOAD_SIZE_DEFAULT,
		allow           => undef,
		upload_dir      => undef,
		%{$params}	# Caller-supplied args override the defaults above
	}, $class;
}

=head2 script_name

lib/CGI/Info.pm  view on Meta::CPAN

If an argument is given twice or more, then the values are put in a comma
separated string.

The returned hash value can be passed into L<CGI::Untaint>.

Takes four optional parameters: allow, logger and upload_dir.
The parameters are passed in a hash, or a reference to a hash.
The latter is more efficient since it puts less on the stack.

Allow is a reference to a hash list of CGI parameters that you will allow.
The value for each entry is either a permitted value,

lib/CGI/Info.pm  view on Meta::CPAN

This works alongside existing regex and Params::Validate::Strict patterns.
A undef value means that any value will be allowed.
Arguments not in the list are silently ignored.
This is useful to help to block attacks on your site.

Upload_dir is a string containing a directory where files being uploaded are to
be stored.
It must be a writeable directory in the temporary area.

Takes an optional parameter logger, which is used for warnings and traces.
It can be an object that understands warn() and trace() messages,
such as a L<Log::Log4perl> or L<Log::Any> object,
a reference to code,
a reference to an array,
or a filename.

The allow, logger and upload_dir arguments can also be passed to the
constructor.

	use CGI::Info;
	use CGI::Untaint;
	# ...

lib/CGI/Info.pm  view on Meta::CPAN

	}

	if(defined($params->{allow})) {
		$self->{allow} = $params->{allow};
	}
	if(defined($params->{upload_dir})) {
		$self->{upload_dir} = $params->{upload_dir};
	}
	if(defined($params->{'logger'})) {
		$self->set_logger($params->{'logger'});
	}
	$self->_trace('Entering params');

lib/CGI/Info.pm  view on Meta::CPAN

		my $content_length = $self->_get_env('CONTENT_LENGTH');
		if((!defined($content_length)) || ($content_length =~ /\D/)) {
			$self->{status} = 411;
			return;
		}
		if(($self->{max_upload_size} >= 0) && ($content_length > $self->{max_upload_size})) {	# Set maximum posts
			# TODO: Design a way to tell the caller to send HTTP
			# status 413
			$self->{status} = 413;
			$self->_warn('Large upload prohibited');
			return;
		}

		if((!defined($content_type)) || ($content_type =~ /application\/x-www-form-urlencoded/)) {
			my $buffer;

lib/CGI/Info.pm  view on Meta::CPAN

			# if($ENV{'QUERY_STRING'}) {
				# my @getpairs = split(/&/, $ENV{'QUERY_STRING'});
				# push(@pairs, @getpairs);
			# }
		} elsif($content_type =~ /multipart\/form-data/i) {
			if(!defined($self->{upload_dir})) {
				if($ENV{'REMOTE_ADDR'}) {
					# This could be an attack
					$self->_warn({ warning => "$ENV{REMOTE_ADDR}: Attempt to upload a file of $content_length bytes when upload_dir has not been set" });
				} else {
					$self->_warn({ warning => 'Attempt to upload a file when upload_dir has not been set' });
				}
				$self->status(501);	# Not implemented
				return;
			}

			# Validate 'upload_dir'
			# Ensure the upload directory is safe and accessible
			# - Check permissions
			# - Validate path to prevent directory traversal attacks
			# TODO: Consider using a temporary directory for uploads and moving them later
			if(!File::Spec->file_name_is_absolute($self->{upload_dir})) {
				$self->_warn({
					warning => "upload_dir $self->{upload_dir} isn't a full pathname"
				});
				$self->status(500);
				delete $self->{upload_dir};
				return;
			}
			if(!-d $self->{upload_dir}) {
				$self->_warn({
					warning => "upload_dir $self->{upload_dir} isn't a directory"
				});
				$self->status(500);
				delete $self->{upload_dir};
				return;
			}
			if(!-w $self->{upload_dir}) {
				delete $self->{paramref};
				$self->_warn({
					warning => "upload_dir $self->{upload_dir} isn't writeable"
				});
				$self->status(500);
				delete $self->{upload_dir};
				return;
			}
			my $tmpdir = $self->tmpdir();
			if($self->{'upload_dir'} !~ /^\Q$tmpdir\E/) {
				$self->_warn({
					warning => 'upload_dir ' . $self->{'upload_dir'} . " isn't somewhere in the temporary area $tmpdir"
				});
				$self->status(500);
				delete $self->{upload_dir};
				return;
			}
			if($content_type =~ /boundary=(\S+)$/) {
				@pairs = $self->_multipart_data({
					length => $content_length,

lib/CGI/Info.pm  view on Meta::CPAN

				# [^"]+ instead of .+ : stops at first '"' without backtracking,
				# and cannot accidentally capture across the closing delimiter.
				if($field =~ /filename="([^"]+)?"/) {
					my $filename = $1;
					unless(defined($filename)) {
						$self->_warn('No upload filename given');
					} elsif($filename =~ /[\\\/\|]/) {
						$self->_warn("Disallowing invalid filename: $filename");
					} else {
						$filename = $self->_create_file_name({
							filename => $filename
						});

						# Don't do this since it taints the string and I can't work out how to untaint it
						# my $full_path = Cwd::realpath(File::Spec->catfile($self->{upload_dir}, $filename));
						# $full_path =~ m/^(\/[\w\.]+)$/;
						my $full_path = File::Spec->catfile($self->{upload_dir}, $filename);
						unless(open($fout, '>', $full_path)) {
							$self->_warn("Can't open $full_path");
						}
						$writing_file = 1;
						push(@pairs, "$key=$filename");

lib/CGI/Info.pm  view on Meta::CPAN

	return @pairs;
}

# Robust filename generation (preventing overwriting).
# Previously used "! -e $rc" which checked existence in the CURRENT WORKING
# DIRECTORY, not the upload directory — a logic bug and a TOCTOU race.
# Now checks in the actual upload directory and caps iterations to avoid
# an infinite loop if the directory fills up.
sub _create_file_name :Protected {
	my ($self, $args) = @_;

	my $upload_dir = $self->{upload_dir};
	my $filename   = $$args{filename} . '_' . time;

	my $counter = 0;
	my $rc;
	do {
		$rc = $filename . ($counter ? "_$counter" : '');
		$counter++;
		# Check in upload_dir when set; otherwise check relative to CWD.
		# File::Spec->catfile('', ...) produces an absolute path, so we
		# must not pass an empty string as the directory component.
	} until(
		! -e ($upload_dir ? File::Spec->catfile($upload_dir, $rc) : $rc)
		|| $counter > 1000
	);
	if($counter > 1000) {
		Carp::croak('_create_file_name: unable to find a unique filename after 1000 attempts');
	}

lib/CGI/Info.pm  view on Meta::CPAN


  -- Normal (non-clone) path
  new(class, params) ^=
    let configured == Object::Configure::configure(class, params)
    in  CGIInfo {
          max_upload_size |-> configured.max_upload_size ?? MAX_UPLOAD_SIZE_DEFAULT,
          allow           |-> configured.allow ?? null,
          upload_dir      |-> configured.upload_dir ?? null,
          ...configured
        }

  -- Pre-conditions
  pre new(class, params) ^=

 view all matches for this distribution


CGI-Lazy

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

0.03	-split Authn.pm and Authz.pm ito separate distros
	-lowered requirements in Makefile.PL  they were unnecessarily high

0.02-r3 -fixed pod formatting again.  no changes to code

0.02-r2 -uploaded partial distro to CPAN  oops.

0.02	Sat Aug 2
	-reformatted POD so it will display on cpan
	-pulled ModPerl.pm from distribution so tests pass.  ModPerl will be distributed separately

 view all matches for this distribution


CGI-Lite-Request

 view release on metacpan or  search on metacpan

lib/CGI/Lite/Request.pm  view on Meta::CPAN

  $req->content_type('text/html');              # set
  $req->content_type;                           # get
  $path = $req->path_info;                      # $ENV{PATH_INFO}
  $cookie = $req->cookie('my_cookie');          # fetch or create a cookie
  $req->cookie('SID')->value($sessid);          # set a cookie
  $upload = $req->upload('my_field');           # CGI::Lite::Upload instance
  $uploads = $req->uploads;                     # hash ref of CGI::Lite::Upload objects

=head1 DESCRIPTION

This module extends L<CGI::Lite> to provide an interface which is compatible with the most commonly used
methods of L<Apache::Request> as a fat free alternative to L<CGI>.

lib/CGI/Lite/Request.pm  view on Meta::CPAN

        $sessid = $req->cookies->{'SID'}->value;
    }

see L<CGI::Lite::Request::Cookie> for more details

=item upload

returns a named L<CGI::Lite::Upload> object keyed on the field name
with which it was associated when uploaded.

=item uploads

returns a hash reference of all the L<CGI::Lite::Request::Upload> objects
keyed on their names.

see L<CGI::Lite::Request::Upload> for details

 view all matches for this distribution


CGI-Lite

 view release on metacpan or  search on metacpan

lib/CGI/Lite.pm  view on Meta::CPAN

        die $message;
    }

=head1 DESCRIPTION

This module can be used to decode form data, query strings, file uploads
and cookies in a very simple manner.

It has only one dependency and is therefore relatively fast to
instantiate. This makes it well suited to a non-persistent CGI scenario.

lib/CGI/Lite.pm  view on Meta::CPAN

method as a scalar string to force CGI::Lite to decode the information in 
a specific manner. 

	my $params = $cgi->parse_form_data ('GET');

For multipart/form-data, uploaded files are stored in the user selected 
directory (see L<set_directory|/set_directory>). If timestamp mode is on (see 
L<add_timestamp|/add_timestamp>), the files are named in the following format:

    timestamp__filename

lib/CGI/Lite.pm  view on Meta::CPAN


=head2 set_platform

This method is used to set the platform on which the web server is
running. CGI::Lite uses this information to translate end-of-line
(EOL) characters for uploaded files (see the L<add_mime_type|/add_mime_type> and
L<remove_mime_type|/remove_mime_type> methods) so that they are accounted for properly on
that platform.

    $cgi->set_platform ($platform);

lib/CGI/Lite.pm  view on Meta::CPAN


    my $size_limit = $cgi->set_size_limit (10_000_000);

Returns the new value if provided, otherwise the existing value.

=head2 deny_uploads

To prevent any file uploads simply call this method with an argument of
1. To enable them again, use an argument of zero.

    my $deny_uploads = $cgi->deny_uploads (1);

Returns the new value if provided, otherwise the existing value.

=head2 force_unique_cookies

lib/CGI/Lite.pm  view on Meta::CPAN


Returns the new value if provided, otherwise the existing value.

=head2 set_directory

Used to set the directory where the uploaded files will be stored 
(only applies to the I<multipart/form-data> encoding scheme).

    my $tmpdir = '/some/dir';
    $cgi->set_directory ($tmpdir) or
        die "Directory $tmpdir cannot be used.\n";

lib/CGI/Lite.pm  view on Meta::CPAN


=head2 close_all_files

    $cgi->close_all_files;

All uploaded files that are opened as a result of calling L<set_file_type|/set_file_type>
with the "handle" argument can be closed in one shot by calling this
method which takes no arguments and returns undef.

=head2 add_mime_type

By default, EOL characters are translated for all uploaded files
with specific MIME types (i.e. text/plain, text/html, etc.).
This method can be used to add to the list of MIME types. For example,
if you want CGI::Lite to translate EOL characters for uploaded
files of I<application/mac-binhex40>, then you would do this:

    $cgi->add_mime_type ('application/mac-binhex40');

Returns 1 if this MIME type is newly added, 0 otherwise.

=head2 remove_mime_type

This method is the converse of L<add_mime_type|/add_mime_type>. It allows for the
removal of a particular MIME type. For example, if you do not want 
CGI::Lite to translate EOL characters for uploaded files of type I<text/html>, 
then you would do this:

    $cgi->remove_mime_type ('text/html');

Returns 1 if this MIME type is newly deleted, 0 otherwise.

lib/CGI/Lite.pm  view on Meta::CPAN

Returns the list of the 
MIME types for which EOL translation is performed.

    my @mimelist = $cgi->get_mime_types ();

=head2 get_upload_type

Returns the MIME type of uploaded data. Takes the field name as a scalar
argument. This previously undocumented function was named print_mime_type
prior to version 3.0.

    my $this_type = $cgi->get_upload_type ($field);

Returns the MIME type as a scalar string if single valued, an arrayref
if multi-valued or undef if the argument does not exist or has no type.

=head2 set_file_type

The I<names> of uploaded files are returned by default when
the L<parse_form_data|/parse_form_data> method is called . But if this method is passed the string "handle" as its argument beforehand then
the I<handles> to the files are returned instead. However, the name
of each handle still corresponds to the filename.

    # $fh has been set to one of 'handle' or 'file'

lib/CGI/Lite.pm  view on Meta::CPAN

This function should be called I<before> any call to L<parse_form_data|/parse_form_data>, or 
else it will have no effect.

=head2 add_timestamp

By default, a timestamp is added to the front of uploaded files. 
However, there is the option of completely turning off timestamp mode
(value 0), or adding a timestamp only for existing files (value 2).

    $cgi->add_timestamp ($tsflag);	
    # where $tsflag takes one of these values

lib/CGI/Lite.pm  view on Meta::CPAN

    #       1 = timestamp all files (default)
    #       2 = timestamp only if file exists

=head2 filter_filename

This method is used to change the manner in which uploaded
files are named. For example, if you want uploaded filenames
to be all upper case, you can use the following code:

    $cgi->filter_filename (\&make_uppercase);
    $cgi->parse_form_data;

lib/CGI/Lite.pm  view on Meta::CPAN

		all_handles     => [],
		error_status    => 0,
		error_message   => undef,
		file_size_limit => 2097152,    # Unused as yet
		size_limit      => -1,
		deny_uploads    => 0,
		unique_cookies  => 0,
	};

	$self->{convert} = {
		'text/html'  => 1,

lib/CGI/Lite.pm  view on Meta::CPAN

sub Version
{
	return $VERSION;
}

sub deny_uploads
{
	my ($self, $newval) = @_;
	if (defined $newval) {
		$self->{deny_uploads} = $newval ? 1 : 0;
	}
	return $self->{deny_uploads};
}

sub set_size_limit
{
	my ($self, $limit) = @_;

lib/CGI/Lite.pm  view on Meta::CPAN


			return wantarray ? %{$self->{web_data}} : $self->{web_data};

		} elsif ($content_type =~ /multipart\/form-data/) {

			if ($self->{deny_uploads}) {
				$self->_error ("multipart/form-data unacceptable when "
					  . "deny_uploads is set");
				return;
			}
			($boundary) = $content_type =~ /boundary=(\S+)$/;
			$self->_parse_multipart_data ($content_length, $boundary);

lib/CGI/Lite.pm  view on Meta::CPAN

			print "$key = $value$eol";
		}
	}
}

sub get_upload_type
{
	my ($self, $field) = @_;

	return ($self->{'mime_types'}->{$field});
}

 view all matches for this distribution


CGI-Minimal

 view release on metacpan or  search on metacpan

lib/CGI/Minimal.pod  view on Meta::CPAN


Provides a micro-weight alternative to the CGI.pm module

Rather than attempt to address every possible need of a CGI
programmer, it provides the _minimum_ functions needed for CGI such
as form decoding (including file upload forms), URL encoding
and decoding, HTTP usable date generation (RFC1123 compliant
dates) and I<basic> escaping and unescaping of HTMLized text.

The ':preload' use time option is used to force all sub-component
modules to load at compile time.  It is not required for

lib/CGI/Minimal.pod  view on Meta::CPAN


=item truncated;

Returns '1' if the read form was shorter than the
Content-Length that was specified by the submitting
user agent (ie the data from a form uploaded by a
web browser was cut off before all the data was received).

Returns '0' if the form was NOT truncated.

Example:

  use CGI::Minimal;

  my $cgi = CGI::Minimal->new;
  if ($cgi->truncated) {
    &bad_form_upload;
  } else {
    &good_form_upload;
  }

'truncated' will also return '1' if the form length
received would have exceeded the set 'max_read_length'.

 view all matches for this distribution


CGI-MxScreen

 view release on metacpan or  search on metacpan

MxScreen/Config.pm  view on Meta::CPAN

	{
		package CGI::MxScreen::cf;
		no strict 'vars';

		$fatals_to_browser = 1;
		$disable_upload = 1;
		$view_source = 1;
		$mx_check_vars = 1;
		$mx_buffer_stdout = 1;
	}
	return DVOID;

MxScreen/Config.pm  view on Meta::CPAN

		$datum_config = "$Bin/$datum_config" unless $datum_config =~ m|^/|;
		DLOAD_CONFIG(-file => $datum_config) if -f $datum_config;
	}

	#
	# "disable_upload" and "post_max"
	#

	$CGI::DISABLE_UPLOADS = 1
		if $CGI::MxScreen::cf::disable_upload;
	$CGI::POST_MAX = $CGI::MxScreen::cf::post_max || 1024 * 1024;

	#
	# "fatals_to_browser" and "fatal_message"
	#

MxScreen/Config.pm  view on Meta::CPAN

 use CGI::MxScreen::Config "./filename.pl";
 use CGI::MxScreen::Config ({ -FILE => "./filename.pl" });

 use CGI::MxScreen::Config ({
     -FILE              => "./filename.pl",  # Common init
     -disable_upload    => 0,                # Supersede common init
     -fatals_to_browser => 0,
     -loglevel          => "debug",
 });

=head1 DESCRIPTION

MxScreen/Config.pm  view on Meta::CPAN

=item datum_on

When true, activates C<Carp::Datum>.  Note that the C<datum_config> variable
is used to load the configuration even when this variable is set to false.

=item disable_upload

Sets C<$CGI::DISABLE_UPLOADS> to true if set.

=item fatal_message

MxScreen/Config.pm  view on Meta::CPAN


=head1 EXAMPLE

Here is a configuration file example:

    $disable_upload = 1;
    $post_max = 10 * 1024;
    
    $fatals_to_browser = 1;
    
    $datum_config = "debug.cf";

 view all matches for this distribution


CGI-PSGI

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN


0.12  Mon Oct 25 11:06:59 PDT 2010
        - Strip Status: header since to conform PSGI spec (clkao)

0.11  Sat May  1 04:37:07 PDT 2010
        - Upped CGI.pm dependency to 3.33 to fix the upload() issue in perl 5.10

0.10  Wed Mar 31 01:14:43 PDT 2010
        - Upped CGI.pm dependency to 3.15, released in 2005 and is core in perl 5.8.8

0.09  Thu Feb 11 14:47:26 PST 2010

Changes  view on Meta::CPAN


0.06  Wed Jan  6 18:12:45 PST 2010
        - Added ->env method to access PSGI env from the object.

0.05  Wed Jan  6 00:37:23 PST 2010
        - Fixed a bug where uploaded files are not saved in temp files (fujiwara)

0.04  Wed Dec  9 16:37:47 PST 2009
        - Added virtual_host to the list because bad CGI.pm uses host() as a function not a method (kazuho)

0.03  Fri Nov 27 17:32:50 JST 2009

 view all matches for this distribution


CGI-Plus

 view release on metacpan or  search on metacpan

lib/CGI/Plus.pm  view on Meta::CPAN


# Debug::ShowStuff
# use Debug::ShowStuff ':all';
# use Debug::ShowStuff::ShowVar;

# enable file uploads
$CGI::DISABLE_UPLOADS = 0;

# maximum upload: 5 mb
$CGI::POST_MAX = 5 * 1024 * 1024;

# set path to empty string
$ENV{'PATH'} = '';

lib/CGI/Plus.pm  view on Meta::CPAN


Initial release

=item Version 0.12    November 28, 2012

Fixing prerequisite lists in CPAN upload.

=item Version 0.13    April 25, 2014

Fixed error in META.yml.

 view all matches for this distribution


CGI-ProgressBar

 view release on metacpan or  search on metacpan

lib/CGI/ProgressBar.pm  view on Meta::CPAN

on the below, and it seems that the hook is called more times
than necessary....

=head2 PROCESS

The script has to both upload and process a file.

The hook script is called when the object is constructed,
thus before any headers can be output. There the hook needs
to output its own headers, and we only output headers for
the 'select file' page when the hook has not been called.

lib/CGI/ProgressBar.pm  view on Meta::CPAN

		$cgi->start_html( -title=>'A Simple Example', ),
		$cgi->h1('Simple Upload-hook Example');
	}

	print $cgi->start_form( -enctype=>'application/x-www-form-urlencoded'),
		$cgi->filefield( 'uploaded_file'),
		$cgi->submit,
		$cgi->end_form,p;

	if ($cgi->param('uploaded_file')){
		print 'uploaded_file: '.param('uploaded_file');
	}


	sub bar_hook {
		my ($filename, $buffer, $bytes, $data) = @_;

 view all matches for this distribution


CGI-Prototype-Mecha

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

	 Urgh.  Apparently IO::String breaks on 5.6.x, so falling
	 back to File::Temp.

0.20	 Wed May 11 19:20:36 EDT 2005
	 Teach CGI::Prototype::Mecha how to handle every possible request
	 including file-upload fields!

0.10	 Wed Apr  6 10:47:07 PDT 2005
	 Split out from CGI::Prototype


 view all matches for this distribution


CGI-Pure-Fast

 view release on metacpan or  search on metacpan

Fast.pm  view on Meta::CPAN

 $cgi->append_param('par', 'value');
 my @par_value = $cgi->param('par');
 $cgi->delete_param('par');
 $cgi->delete_all_params;
 my $query_string = $cgi->query_string;
 $cgi->upload('filename', '~/filename');
 my $mime = $cgi->upload_info('filename', 'mime');
 my $query_data = $cgi->query_data;

=head1 METHODS

=over 8

 view all matches for this distribution


CGI-Pure

 view release on metacpan or  search on metacpan

Pure.pm  view on Meta::CPAN

	my $self = bless {}, $class;

	# CRLF separator.
	$self->{'crlf'} = undef;

	# Disable upload.
	$self->{'disable_upload'} = 1;

	# Init.
	$self->{'init'} = undef;

	# Parameter separator.

Pure.pm  view on Meta::CPAN

	}
	return join $self->{'par_sep'}, @pairs;
}

# Upload file from tmp.
sub upload {
	my ($self, $filename, $writefile) = @_;
	if ($ENV{'CONTENT_TYPE'} !~ m/^multipart\/form-data/ismx) {
		err 'File uploads only work if you specify '.
			'enctype="multipart/form-data" in your form.';
	}
	if (! $filename) {;
		if ($writefile) {
			err 'No filename submitted for upload to '.
				"'$writefile'.";
		}
		return $self->{'.filehandles'}
			? keys %{$self->{'.filehandles'}} : ();
	}

Pure.pm  view on Meta::CPAN

		}
		$self->{'.filehandles'}->{$filename} = undef;
		undef $fh;
	} else {
		err "No filehandle for '$filename'. ".
			'Are uploads enabled (disable_upload = 0)? '.
			'Is post_max big enough?';
	}
	return;
}

# Return informations from uploaded files.
sub upload_info {
	my ($self, $filename, $info) = @_;
	if ($ENV{'CONTENT_TYPE'} !~ m/^multipart\/form-data/ismx) {
		err 'File uploads only work if you '.
			'specify enctype="multipart/form-data" in your '.
			'form.';
	}
	if (! $filename) {
		return keys %{$self->{'.tmpfiles'}};

Pure.pm  view on Meta::CPAN

sub _save_tmpfile {
	my ($self, $boundary, $filename, $got_data_length, $data) = @_;
	my $fh;
	my $CRLF = $self->_crlf;
	my $file_size = 0;
	if ($self->{'disable_upload'}) {
		err '405 Not Allowed - File uploads are disabled.';
	} elsif ($filename) {
		eval {
			require IO::File;
		};
		if ($EVAL_ERROR) {

Pure.pm  view on Meta::CPAN

		if ("$buffer$data" =~ m/$boundary/ms) {
			$data = $buffer.$data;
			last;
		}

		# BUG: Fixed hanging bug if browser terminates upload part way.
		if (! $data) {
			undef $fh;
			err '400 Malformed multipart, no terminating '.
				'boundary.';
		}

Pure.pm  view on Meta::CPAN

 $cgi->append_param('par', 'value');
 my @par_value = $cgi->param('par');
 $cgi->delete_param('par');
 $cgi->delete_all_params;
 my $query_string = $cgi->query_string;
 $cgi->upload('filename', '~/filename');
 my $mime = $cgi->upload_info('filename', 'mime');
 my $query_data = $cgi->query_data;

=head1 METHODS

=over 8

Pure.pm  view on Meta::CPAN


 Constructor

=over 8

=item * C<disable_upload>

 Disables file upload.
 Default value is 1.

=item * C<init>

 Initialization variable.

Pure.pm  view on Meta::CPAN


=item C<query_string()>

 Returns actual query string.

=item C<upload($filename, [$write_to])>

 Upload file from tmp.
 upload() returns array of uploaded filenames.
 upload($filename) returns handler to uploaded filename.
 upload($filename, $write_to) uploads temporary '$filename' file to
 '$write_to' file.

=item C<upload_info($filename, [$info])>

 Returns informations from uploaded files.
 upload_info() returns array of uploaded files.
 upload_info('filename') returns size of uploaded 'filename' file.
 upload_info('filename', 'mime') returns mime type of uploaded 'filename' file.

=back

=head1 ERRORS

 new():
         400 Malformed multipart, no terminating boundary.
         400 No boundary supplied for multipart/form-data.
         405 Not Allowed - File uploads are disabled.
         413 Request entity too large: %s bytes on STDIN exceeds post_max !
         500 Bad read! wanted %s, got %s.
         500 IO::File can\'t create new temp_file.
         500 IO::File is not available %s.
         Bad parameter separator '%s'.

Pure.pm  view on Meta::CPAN

                 Unknown parameter '%s'.

 append_param():
         Parameter '%s' has bad value.

 upload():
         Cannot close file '%s': %s.
         Cannot write file '%s': %s.
         File uploads only work if you specify enctype="multipart/form-data" in your form.
         No filehandle for '%s'. Are uploads enabled (disable_upload = 0)? Is post_max big enough?
         No filename submitted for upload to '$writefile'.

 upload_info():
         File uploads only work if you specify enctype="multipart/form-data" in your form.


=head1 EXAMPLE1

 use strict;

 view all matches for this distribution


CGI-Safe

 view release on metacpan or  search on metacpan

lib/CGI/Safe.pm  view on Meta::CPAN


    # Clean up the environment and establish some defaults
    $shell = $ENV{'SHELL'};
    $path  = $ENV{'PATH'};
    delete @ENV{qw/ IFS CDPATH ENV BASH_ENV PATH SHELL /};
    $CGI::DISABLE_UPLOADS = 1;             # Disable uploads
    $CGI::POST_MAX        = 512 * 1024;    # limit posts to 512K max
}

sub import {
    if ( grep { /:(?:standard|cgi)/ } @_ ) {

lib/CGI/Safe.pm  view on Meta::CPAN

 my $q = CGI::Safe->new;

=head1 DESCRIPTION

If you've been working with CGI.pm for any length of time, you know that it
allows uploads by default and does not have a maximum post size. Since it
saves the uploads as a temp file, someone can simply upload enough data to fill
up your hard drive to initiate a DOS attack. To prevent this, we're regularly
warned to include the following two lines at the top of our CGI scripts:

 $CGI::DISABLE_UPLOADS = 1;          # Disable uploads
 $CGI::POST_MAX        = 512 * 1024; # limit posts to 512K max

As long as those are their before you instantiate a CGI object (or before you
access param and related CGI functions with the function oriented interface),
you have pretty safely plugged this problem. However, most CGI scripts don't

lib/CGI/Safe.pm  view on Meta::CPAN

 use CGI::Safe qw/ :standard taint /;
 $CGI::DISABLE_UPLOADS = 0;

=head2 Uploads and Maximum post size

As mentioned earlier, most scripts that do not need uploading should have
something like the following at the start of their code to disable uploads:

 $CGI::DISABLE_UPLOADS = 1;          # Disable uploads
 $CGI::POST_MAX        = 512 * 1024; # limit posts to 512K max

The C<CGI::Safe> sets these values in an C<BEGIN{}> block.  If necessary, the
programmer can override these values two different ways.  When using the
function oriented interface, if needing file uploads and wanting to allow up
to a 1 megabyte upload, they would set these values directly I<before> using
any of the CGI.pm CGI functions:

 use CGI::Safe qw/ :standard taint /;
 $CGI::DISABLE_UPLOADS = 0;
 $CGI::POST_MAX        = 1_024 * 1_024; # limit posts to 1 meg max

 view all matches for this distribution


CGI-SecureState

 view release on metacpan or  search on metacpan

SecureState.pm  view on Meta::CPAN


=item B<Extra and Paranoid Security>

If the standard security is not enough, CGI::SecureState provides extra security
by setting the appropriate options in CGI.pm.  The ":extra_security" option
enables private file uploads and sets the maximum size for a CGI POST to be
10 kilobytes.  The ":paranoid_security" option disables file uploads entirely.
To use them, do
    use CGI::SecureState qw(:extra_security);  #or
    use CGI::SecureState qw(:paranoid_security);

To disable them, do

 view all matches for this distribution


CGI-Session-ExpireSessions

 view release on metacpan or  search on metacpan

Changelog.ini  view on Meta::CPAN

EOT

[V 1.09]
Date=2008-05-15T11:11:00
Comments= <<EOT
- Delete V 1.08 from CPAN and upload V 1.09, hoping CPAN will index it properly this time.
All this because some uses have logged a ticket (RT#35515) about not being able
to use 'cpan' to install the module. They are right, I can't get 'cpan' to work either
- Start shipping Changelog.ini
EOT

[V 1.08]
Date=2006-06-12T11:32:00
Comments= <<EOT
- Version 1.07 was never uploaded to CPAN. It was just available from my site, and was meant
for testing the proposed callback mechanism in CGI::Session::find. That mechanism was
changed before CGI::Session 4.14 was released, so my module's code now changes to match.
Also, since CGI::Session has been patched so its sub find() no longer updates the session's
access time, my module now uses atime instead of ctime when checking for expiry
EOT

 view all matches for this distribution


CGI-Simple

 view release on metacpan or  search on metacpan

lib/CGI/Simple.pm  view on Meta::CPAN

  if ( $USE_CGI_PM_DEFAULTS ) {
    _use_cgi_pm_global_settings();
    return;
  }

  # no file uploads by default, set to 0 to enable uploads
  $DISABLE_UPLOADS = 1
   unless defined $DISABLE_UPLOADS;

  # use a post max of 100K, set to -1 for no limits
  $POST_MAX = 102_400

lib/CGI/Simple.pm  view on Meta::CPAN

  my ( $self, @args ) = @_;

# arguments supplied in the 'use CGI::Simple [ARGS];' will now be in @args
  foreach ( @args ) {
    $USE_CGI_PM_DEFAULTS = 1, next if m/^-default/i;
    $DISABLE_UPLOADS     = 1, next if m/^-no.?upload/i;
    $DISABLE_UPLOADS     = 0, next if m/^-upload/i;
    $HEADERS_ONCE        = 1, next if m/^-unique.?header/i;
    $NPH                 = 1, next if m/^-nph/i;
    $DEBUG               = 0, next if m/^-no.?debug/i;
    $DEBUG = defined $1 ? $1 : 2, next if m/^-debug(\d)?/i;
    $USE_PARAM_SEMICOLONS = 1, next if m/^-newstyle.?url/i;

lib/CGI/Simple.pm  view on Meta::CPAN


    BOUNDARY:

    while ( $data =~ m/^$boundary$CRLF/ ) {
      ## TAB and high ascii chars are definitivelly allowed in headers.
      ## Not accepting them in the following regex prevents the upload of
      ## files with filenames like "España.txt".
      # next READ unless $data =~ m/^([\040-\176$CRLF]+?$CRLF$CRLF)/o;
      next READ
       unless $data =~ m/^([\x20-\x7E\x80-\xFF\x09$CRLF]+?$CRLF$CRLF)/o;
      my $header = $1;

lib/CGI/Simple.pm  view on Meta::CPAN

        $data =~ s/^\Q$header\E//;
        ( $got_data, $data, my $fh, my $size )
         = $self->_save_tmpfile( $handle, $boundary, $filename,
          $got_data, $data );
        $self->_add_param( $param, $filename );
        $self->{'.upload_fields'}->{$param} = $filename;
        $self->{'.filehandles'}->{$filename} = $fh if $fh;
        $self->{'.tmpfiles'}->{$filename}
         = { 'size' => $size, 'mime' => $mime }
         if $size;
        next BOUNDARY;

lib/CGI/Simple.pm  view on Meta::CPAN

  my $fh;
  my $CRLF      = $self->crlf;
  my $length    = $ENV{'CONTENT_LENGTH'} || 0;
  my $file_size = 0;
  if ( $self->{'.globals'}->{'DISABLE_UPLOADS'} ) {
    $self->cgi_error( "405 Not Allowed - File uploads are disabled" );
  }
  elsif ( $filename ) {
    eval { require IO::File };
    $self->cgi_error( "500 IO::File is not available $@" ) if $@;
    $fh = new_tmpfile IO::File;

lib/CGI/Simple.pm  view on Meta::CPAN

     unless $fh;
  }

# read in data until closing boundary found. buffer to catch split boundary
# we do this regardless of whether we save the file or not to read the file
# data from STDIN. if either uploads are disabled or no file has been sent
# $fh will be undef so only do file stuff if $fh is true using $fh && syntax
  $fh && binmode $fh;
  while ( $got_data < $length ) {

    my $buffer = $data;
    last unless _internal_read( $self, \*STDIN, $data );

    # fixed hanging bug if browser terminates upload part way through
    # thanks to Brandon Black
    unless ( $data ) {
      $self->cgi_error(
        '400 Malformed multipart, no terminating boundary' );
      undef $fh;

lib/CGI/Simple.pm  view on Meta::CPAN

  $self->_store_globals;
}

sub Delete_all { $_[0]->delete_all }        # as used by CGI.pm

sub upload {
  my ( $self, $filename, $writefile ) = @_;
  unless ( $filename ) {
    $self->cgi_error( "No filename submitted for upload to $writefile" )
     if $writefile;
    return $self->{'.filehandles'}
     ? keys %{ $self->{'.filehandles'} }
     : ();
  }
  unless ( $ENV{'CONTENT_TYPE'} =~ m|^multipart/form-data|i ) {
    $self->cgi_error(
      'Oops! File uploads only work if you specify ENCTYPE="multipart/form-data" in your <FORM> tag'
    );
    return undef;
  }
  my $fh = $self->{'.filehandles'}->{$filename};

  # allow use of upload fieldname to get filehandle
  # this has limitation that in the event of duplicate
  # upload field names there can only be one filehandle
  # which will point to the last upload file
  # access by filename does not suffer from this issue.
  $fh
   = $self->{'.filehandles'}->{ $self->{'.upload_fields'}->{$filename} }
   if !$fh and defined $self->{'.upload_fields'}->{$filename};

  if ( $fh ) {
    seek $fh, 0, 0;    # get ready for reading
    return $fh unless $writefile;
    my $buffer;

lib/CGI/Simple.pm  view on Meta::CPAN

    undef $fh;
    return 1;
  }
  else {
    $self->cgi_error(
      "No filehandle for '$filename'. Are uploads enabled (\$DISABLE_UPLOADS = 0)? Is \$POST_MAX big enough?"
    );
    return undef;
  }
}

sub upload_fieldnames {
  my ( $self ) = @_;
  return wantarray
   ? ( keys %{ $self->{'.upload_fields'} } )
   : [ keys %{ $self->{'.upload_fields'} } ];
}

# return the file size of an uploaded file
sub upload_info {
  my ( $self, $filename, $info ) = @_;
  unless ( $ENV{'CONTENT_TYPE'} =~ m|^multipart/form-data|i ) {
    $self->cgi_error(
      'Oops! File uploads only work if you specify ENCTYPE="multipart/form-data" in your <FORM> tag'
    );
    return undef;
  }
  return keys %{ $self->{'.tmpfiles'} } unless $filename;
  return $self->{'.tmpfiles'}->{$filename}->{'mime'}
   if $info =~ /mime/i;
  return $self->{'.tmpfiles'}->{$filename}->{'size'};
}

sub uploadInfo { &upload_info }    # alias for CGI.pm compatibility

# return all params/values in object as a query string suitable for 'GET'
sub query_string {
  my $self = shift;
  my @pairs;

lib/CGI/Simple.pm  view on Meta::CPAN

This document describes CGI::Simple version 1.282.

=head1 SYNOPSIS

    use CGI::Simple;
    $CGI::Simple::POST_MAX = 1024;       # max upload via post default 100kB
    $CGI::Simple::DISABLE_UPLOADS = 0;   # enable uploads

    $q = CGI::Simple->new;
    $q = CGI::Simple->new( { 'foo'=>'1', 'bar'=>[2,3,4] } );
    $q = CGI::Simple->new( 'foo=1&bar=2&bar=3&bar=4' );
    $q = CGI::Simple->new( \*FILEHANDLE );

lib/CGI/Simple.pm  view on Meta::CPAN

    $q->append( -name=>'foo', -value=>['some', 'new', 'values'] );

    $q->delete('foo'); # delete param 'foo' and all its values
    $q->delete_all;    # delete everything

    <INPUT TYPE="file" NAME="upload_file" SIZE="42">

    $files    = $q->upload()                # number of files uploaded
    @files    = $q->upload();               # names of all uploaded files
    $filename = $q->param('upload_file')    # filename of uploaded file
    $mime     = $q->upload_info($filename,'mime'); # MIME type of uploaded file
    $size     = $q->upload_info($filename,'size'); # size of uploaded file

    my $fh = $q->upload($filename);         # get filehandle to read from
    while ( read( $fh, $buffer, 1024 ) ) { ... }

    # short and sweet upload
    $ok = $q->upload( $q->param('upload_file'), '/path/to/write/file.name' );
    print "Uploaded ".$q->param('upload_file')." and wrote it OK!" if $ok;

    $decoded    = $q->url_decode($encoded);
    $encoded    = $q->url_encode($unencoded);
    $escaped    = $q->escapeHTML('<>"&');
    $unescaped  = $q->unescapeHTML('&lt;&gt;&quot;&amp;');

lib/CGI/Simple.pm  view on Meta::CPAN


=head1 DESCRIPTION

CGI::Simple provides a relatively lightweight drop in replacement for CGI.pm.
It shares an identical OO interface to CGI.pm for parameter parsing, file
upload, cookie handling and header generation. This module is entirely object
oriented, however a complete functional interface is available by using the
CGI::Simple::Standard module.

Essentially everything in CGI.pm that relates to the CGI (not HTML) side of
things is available. There are even a few new methods and additions to old

lib/CGI/Simple.pm  view on Meta::CPAN


################ Uploading Files ###################

=head1 FILE UPLOADS

File uploads are easy with CGI::Simple. You use the B<upload()> method.
Assuming you have the following in your HTML:

    <FORM
     METHOD="POST"
     ACTION="http://somewhere.com/cgi-bin/script.cgi"
     ENCTYPE="multipart/form-data">
        <INPUT TYPE="file" NAME="upload_file1" SIZE="42">
        <INPUT TYPE="file" NAME="upload_file2" SIZE="42">
    </FORM>

Note that the ENCTYPE is "multipart/form-data". You must specify this or the
browser will default to "application/x-www-form-urlencoded" which will result
in no files being uploaded although on the surface things will appear OK.

When the user submits this form any supplied files will be spooled onto disk
and saved in temporary files. These files will be deleted when your script.cgi
exits so if you want to keep them you will need to proceed as follows.

=head2 upload() The key file upload method

The B<upload()> method is quite versatile. If you call B<upload()> without
any arguments it will return a list of uploaded files in list context and
the number of uploaded files in scalar context.

    $number_of_files = $q->upload;
    @list_of_files   = $q->upload;

Having established that you have uploaded files available you can get the
browser supplied filename using B<param()> like this:

    $filename1 = $q->param('upload_file1');

You can then get a filehandle to read from by calling B<upload()> and
supplying this filename as an argument. Warning: do not modify the
value you get from B<param()> in any way - you don't need to untaint it.

    $fh = $q->upload( $filename1 );

Now to save the file you would just do something like:

    $save_path = '/path/to/write/file.name';
    open my $out, '>', $save_path or die "Oops $!\n";
    binmode $out;
    print $out $buffer while read( $fh, $buffer, 4096 );
    close $out;

By utilizing a new feature of the upload method this process can be
simplified to:

    $ok = $q->upload( $q->param('upload_file1'), '/path/to/write/file.name' );
    if ($ok) {
        print "Uploaded and wrote file OK!";
    } else {
        print $q->cgi_error();
    }

As you can see upload will accept an optional second argument and will write
the file to this file path. It will return 1 for success and undef if it
fails. If it fails you can get the error from B<cgi_error>

You can also use just the fieldname as an argument to upload ie:

    $fh = $q->upload( 'upload_field_name' );

    or

    $ok = $q->upload( 'upload_field_name', '/path/to/write/file.name' );

BUT there is a catch. If you have multiple upload fields, all called
'upload_field_name' then you will only get the last uploaded file from
these fields.

=head2 upload_info() Get the details about uploaded files

The B<upload_info()> method is a new method. Called without arguments it
returns the number of uploaded files in scalar context and the names of
those files in list context.

    $number_of_upload_files   = $q->upload_info();
    @filenames_of_all_uploads = $q->upload_info();

You can get the MIME type of an uploaded file like this:

    $mime = $q->upload_info( $filename1, 'mime' );

If you want to know how big a file is before you copy it you can get that
information from B<uploadInfo> which will return the file size in bytes.

    $file_size = $q->upload_info( $filename1, 'size' );

The size attribute is optional as this is the default value returned.

Note: The old CGI.pm B<uploadInfo()> method has been deleted.

=head2 $POST_MAX and $DISABLE_UPLOADS

CGI.pm has a default setting that allows infinite size file uploads by
default. In contrast file uploads are disabled by default in CGI::Simple
to discourage Denial of Service attacks. You must enable them before you
expect file uploads to work.

When file uploads are disabled the file name and file size details will
still be available from B<param()> and B<upload_info> respectively but
the upload filehandle returned by B<upload()> will be undefined - not
surprising as the underlying temp file will not exist either.

You can enable uploads using the '-upload' pragma. You do this by specifying
this in you use statement:

    use CGI::Simple qw(-upload);

Alternatively you can enable uploads via the $DISABLE_UPLOADS global like this:

    use CGI::Simple;
    $CGI::Simple::DISABLE_UPLOADS = 0;
    $q = CGI::Simple->new;

lib/CGI/Simple.pm  view on Meta::CPAN

The maximum acceptable data via post is capped at 102_400kB rather than
infinity which is the CGI.pm default. This should be ample for most tasks
but you can set this to whatever you want using the $POST_MAX global.

    use CGI::Simple;
    $CGI::Simple::DISABLE_UPLOADS = 0;      # enable uploads
    $CGI::Simple::POST_MAX = 1_048_576;     # allow 1MB uploads
    $q = CGI::Simple->new;

If you set to -1 infinite size uploads will be permitted, which is the CGI.pm
default.

    $CGI::Simple::POST_MAX = -1;            # infinite size upload

Alternatively you can specify all the CGI.pm default values which allow file
uploads of infinite size in one easy step by specifying the '-default' pragma
in your use statement.

    use CGI::Simple qw( -default ..... );

=head2 binmode() and Win32

If you are using CGI::Simple be sure to call B<binmode()> on any handle that
you create to write the uploaded file to disk. Calling B<binmode()> will do
no harm on other systems anyway.

=cut

################ Miscellaneous Methods ################

lib/CGI/Simple.pm  view on Meta::CPAN

There are a number of pragmas that you can specify in your use CGI::Simple
statement. Pragmas, which are always preceded by a hyphen, change the way
that CGI::Simple functions in various ways. You can generally achieve
exactly the same results by setting the underlying $GLOBAL_VARIABLES.

For example the '-upload' pargma will enable file uploads:

    use CGI::Simple qw(-upload);

In CGI::Simple::Standard Pragmas, function sets , and individual functions
can all be imported in the same use() line.  For example, the following
use statement imports the standard set of functions and enables debugging
mode (pragma -debug):

lib/CGI/Simple.pm  view on Meta::CPAN

See the section on debugging for more details.

=item -default

This sets the default global values for CGI.pm which will enable infinite
size file uploads, and specify the '-newstyle_urls' and '-debug1' pragmas

=item -no_upload

Disable uploads - the default setting

=item - upload

Enable uploads - the CGI.pm default

=item -unique_header

Only allows headers to be generated once per script invocation

lib/CGI/Simple.pm  view on Meta::CPAN



=head2 cgi_error() Retrieving CGI::Simple error messages

Errors can occur while processing user input, particularly when
processing uploaded files.  When these errors occur, CGI::Simple will stop
processing and return an empty parameter list.  You can test for
the existence and nature of errors using the B<cgi_error()> function.
The error messages are formatted as HTTP status codes. You can either
incorporate the error text into an HTML page, or use it as the value
of the HTTP status:

lib/CGI/Simple.pm  view on Meta::CPAN

    $VERSION = "0.01";
    # set this to 1 to use CGI.pm default global settings
    $USE_CGI_PM_DEFAULTS = 0 unless defined $USE_CGI_PM_DEFAULTS;
    # see if user wants old  CGI.pm defaults
    do{ _use_cgi_pm_global_settings(); return } if $USE_CGI_PM_DEFAULTS;
    # no file uploads by default, set to 0 to enable uploads
    $DISABLE_UPLOADS = 1 unless defined $DISABLE_UPLOADS;
    # use a post max of 100K, set to -1 for no limits
    $POST_MAX = 102_400 unless defined $POST_MAX;
    # do not include undefined params parsed from query string
    $NO_UNDEF_PARAMS = 0 unless defined $NO_UNDEF_PARAMS;

lib/CGI/Simple.pm  view on Meta::CPAN

    $NO_NULL  = 1 unless defined $NO_NULL;
    # set behavior when cgi_err() called -1 => silent, 0 => carp, 1 => croak
    $FATAL = -1 unless defined $FATAL;

Four of the default values of the old CGI.pm variables have been changed.
Unlike CGI.pm which by default allows unlimited POST data and file uploads
by default CGI::Simple limits POST data size to 100kB and denies file uploads
by default. $USE_PARAM_SEMICOLONS is set to 0 by default so we use (old style)
& rather than ; as the pair separator for query strings. Debugging is
disabled by default.

There are three new global variables. If $NO_NULL is true (the default) then
CGI::Simple will strip null bytes out of names, values and keywords. Null
bytes can do interesting things to C based code like Perl. Uploaded files
are not touched. $FATAL controls the behavior when B<cgi_error()> is called.
The default value of -1 makes errors silent. $USE_CGI_PM_DEFAULTS reverts the
defaults to the CGI.pm standard values ie unlimited file uploads via POST
for DNS attacks. You can also get the defaults back by using the '-default'
pragma in the use:

    use CGI::Simple qw(-default);
    use CGI::Simple::Standard qw(-default);

lib/CGI/Simple.pm  view on Meta::CPAN

    append
    delete
    Delete
    delete_all
    Delete_all
    upload
    upload_info
    query_string
    parse_query_string
    parse_keywordlist

=head2 Save and Restore from File Methods

lib/CGI/Simple.pm  view on Meta::CPAN

the B<parse_query_string()> method to add the QUERY_STRING data to your object if
the method was POST. The B<no_cache()> method adds an expires now directive and
the Pragma: no-cache directive to the header to encourage some browsers to
do the right thing. B<PrintEnv()> from the cgi-lib.pl routines will dump an
HTML friendly list of the %ENV and makes a handy addition to B<Dump()> for use
in debugging. The upload method now accepts a filepath as an optional second
argument as shown in the synopsis. If this is supplied the uploaded file will
be written to there automagically.

=head2 Internal Routines

    _initialize_globals()

lib/CGI/Simple.pm  view on Meta::CPAN

    _read_data()

=head2 New Public Methods

    add_param()             # adds a param/value(s) pair +/- overwrite
    upload_info()           # uploaded files MIME type and size
    url_decode()            # decode s url encoded string
    url_encode()            # url encode a string
    parse_query_string()    # add QUERY_STRING data to $q object if 'POST'
    no_cache()              # add both the Pragma: no-cache
                            # and Expires/Date => 'now' to header

lib/CGI/Simple.pm  view on Meta::CPAN

    nosticky()
    default_dtd()

=head2 Upload Related

CGI::Simple uses anonymous tempfiles supplied by IO::File to spool uploaded
files to.

    private_tempfiles() # automatic in CGI::Simple
    tmpFileName()       # all upload files are anonymous
    uploadInfo()        # relied on FH access, replaced with upload_info()


=head2 Really Private Subs (marked as so)

    previous_or_default()

 view all matches for this distribution


CGI-Test

 view release on metacpan or  search on metacpan

lib/CGI/Test/Form/Widget.pm  view on Meta::CPAN


Returns true for all buttons that are not boxes.

=item C<is_file>

Returns true for a I<file upload> widget, which allows file selection.

=item C<is_hidden>

Returns true for hidden fields, which have no graphical representation
by definition.

 view all matches for this distribution


CGI-Thin

 view release on metacpan or  search on metacpan

lib/CGI/Thin.pm  view on Meta::CPAN

special feature that it will return an array if the same key is used
twice in the form.  You can force an array even if only one value returned
to avoid complications.

The hash %cgi_data will have all the form data from either a POST or GET form
and will also work for "multipart/form-data" forms necessary for uploading files.

=head1 USAGE

  Functions

lib/CGI/Thin.pm  view on Meta::CPAN

Long headers lines that have been broken over multiple lines in
multipart/form-data don't seem to be handled.

=item *

Large file uploads (like 150MB) will clobber main memory.  One possible addition is
to change how multipart/form-data is read and to spit files directly to the temp directory
and return to the script a filename so it can be retreived from there.

=item *

 view all matches for this distribution


CGI-Tiny

 view release on metacpan or  search on metacpan

lib/CGI/Tiny.pm  view on Meta::CPAN

  my ($self) = @_;
  return [] unless $ENV{CONTENT_TYPE} and $ENV{CONTENT_TYPE} =~ m/^multipart\/form-data\b/i;
  return [map { +{%$_} } @{$self->_body_multipart}];
}

sub uploads      { [map { [@$_] } @{$_[0]->_body_uploads->{ordered}}] }
sub upload_names { [@{$_[0]->_body_uploads->{names}}] }
sub upload       { my $u = $_[0]->_body_uploads->{keyed}; exists $u->{$_[1]} ? $u->{$_[1]}[-1] : undef }
sub upload_array { my $u = $_[0]->_body_uploads->{keyed}; exists $u->{$_[1]} ? [@{$u->{$_[1]}}] : [] }

sub _body_uploads {
  my ($self) = @_;
  unless (exists $self->{body_uploads}) {
    $self->{body_uploads} = {names => \my @names, ordered => \my @ordered, keyed => \my %keyed};
    if ($ENV{CONTENT_TYPE} and $ENV{CONTENT_TYPE} =~ m/^multipart\/form-data\b/i) {
      my $default_charset = $self->{multipart_form_charset};
      $default_charset = 'UTF-8' unless defined $default_charset;
      foreach my $part (@{$self->_body_multipart}) {
        next unless defined $part->{filename};

lib/CGI/Tiny.pm  view on Meta::CPAN

        if (length $default_charset) {
          require Encode;
          $name = Encode::decode($default_charset, "$name");
          $filename = Encode::decode($default_charset, "$filename");
        }
        my $upload = {
          filename     => $filename,
          size         => $size,
          content_type => $headers->{'content-type'},
        };
        $upload->{file} = $file if defined $file;
        $upload->{content} = $content if defined $content;
        push @names, $name unless exists $keyed{$name};
        push @ordered, [$name, $upload];
        push @{$keyed{$name}}, $upload;
      }
    }
  }
  return $self->{body_uploads};
}

sub _body_length {
  my ($self) = @_;
  my $limit = $self->{request_body_limit};

 view all matches for this distribution


( run in 2.871 seconds using v1.01-cache-2.11-cpan-b16cb0d3907 )