Data::FormValidator::Constraints::Upload - Validate File Uploads |
Data::FormValidator::Constraints::Upload - Validate File Uploads
# Be sure to use a CGI.pm object as the form input # when using this constraint my $q = new CGI; my $dfv = Data::FormValidator->check($q,$my_profile);
# In a Data::FormValidator Profile: validator_packages => [qw(Data::FormValidator::Constraints::Upload)], constraints => { image_name => [ { constraint_method => 'file_format', params => [], }, { constraint_method => 'file_max_bytes', params => [\100], }, { constraint_method => 'image_max_dimensions', params => [\200,\200], },
], }
Note: This is a new module is a new addition to Data::FormValidator and is should be considered ``Beta''.
These module is meant to be used in conjunction with the Data::FormValidator module to automate the task of validating uploaded files. The following validation routines are supplied.
To use any of them, the input data passed to Data::FormValidator must be a CGI.pm object.
optional hash reference of parameters. A key named I<mime_types> points to array refererences of valid values.
constraint_method => 'file_format', params => [{ mime_types => [qw!image/jpeg image/gif image/png!], }],
Calling this function sets some meta data which can be retrieved through
the meta()
method of the Data::FormValidator::Results object.
The meta data added is extension
and mime_type
.
The MIME type of the file will first be tried to figured out by using the <File::MMagic> module to examine the file. If that doesn't turn up a result, we'll use a MIME type from the browser if one has been provided. Otherwise, we give up. The extension we return is based on the MIME type we found, rather than trusting the one that was uploaded.
reference to max file size in bytes
constraint_method => 'file_max_bytes', params => [\1024], # 1 k
Calling this function sets some meta data which can be retrieved through
the meta()
method of the Data::FormValidator::Results object.
The meta data added is bytes
.
reference to max pixel width reference to max pixel height
constraint_method => 'image_max_dimensions', params => [\200,\200],
Calling this function sets some meta data which can be retrieved through
the meta()
method of the Data::FormValidator::Results object.
The meta data added is width
and height
.
FileMetadata, the Data::FormValidator manpage, the CGI manpage, the perl manpage
Mark Stosberg, <mark@summersault.com>
Copyright 2003 by Mark Stosberg
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Data::FormValidator::Constraints::Upload - Validate File Uploads |