1Data::FormValidator::CoUnssetrraCionnttsr:i:bUuptDleaodtaadP:(e:3rF)lorDmoVcaulmiednattaotri:o:nConstraints::Upload(3)
2
3
4

NAME

6       Data::FormValidator::Constraints::Upload - Validate File Uploads
7

SYNOPSIS

9           # Be sure to use a CGI.pm or CGI::Simple object as the form
10           # input when using this constraint
11           my $q = CGI->new;
12
13           use Data::FormValidator::Constraints::Upload qw(
14                   file_format
15                   file_max_bytes
16                   image_max_dimensions
17                   image_min_dimensions
18           );
19           my $dfv = Data::FormValidator->check($q,$my_profile);
20
21           # In a Data::FormValidator Profile:
22           constraint_methods => {
23               image_name => [
24                   file_format(),
25                   file_max_bytes(10),
26                   image_max_dimensions(200,200),
27                   image_min_dimensions(100,100),
28                ],
29           }
30

DESCRIPTION

32       Note: This is a new module is a new addition to Data::FormValidator and
33       is should be considered "Beta".
34
35       These module is meant to be used in conjunction with the
36       Data::FormValidator module to automate the task of validating uploaded
37       files. The following validation routines are supplied.
38
39       To use any of them, the input data passed to Data::FormValidator must
40       be a CGI.pm object.
41
42       file_format
43           This function checks the format of the file, based on the MIME type
44           if it's available, and a case-insensitive version of the file
45           extension otherwise. By default, it tries to validate JPEG, GIF and
46           PNG images. The params are:
47
48            optional hash reference of parameters. A key named I<mime_types> points to
49            array references of valid values.
50
51              file_format( mime_types => [qw!image/jpeg image/gif image/png!] );
52
53           Calling this function sets some meta data which can be retrieved
54           through the "meta()" method of the Data::FormValidator::Results
55           object.  The meta data added is "extension" and "mime_type".
56
57           The MIME type of the file will first be tried to figured out by
58           using the <File::MMagic> module to examine the file. If that
59           doesn't turn up a result, we'll use a MIME type from the browser if
60           one has been provided. Otherwise, we give up. The extension we
61           return is based on the MIME type we found, rather than trusting the
62           one that was uploaded.
63
64           NOTE: if we have to fall back to using the MIME type provided by
65           the browser, we access it from the original input data and not the
66           filtered data.  This should only cause issue when you have used a
67           filter to alter the type of file that was uploaded (e.g. image
68           conversion).
69
70       file_max_bytes
71           This function checks the maximum size of an uploaded file. By
72           default, it checks to make sure files are smaller than 1 Meg. The
73           params are:
74
75            reference to max file size in bytes
76
77               file_max_bytes(1024), # 1 k
78
79           Calling this function sets some meta data which can be retrieved
80           through the "meta()" method of the Data::FormValidator::Results
81           object.  The meta data added is "bytes".
82
83       image_max_dimensions
84           This function checks to make sure an uploaded image is no longer
85           than some maximum dimensions. The params are:
86
87            reference to max pixel width
88            reference to max pixel height
89
90               image_max_dimensions(200,200),
91
92           Calling this function sets some meta data which can be retrieved
93           through the "meta()" method of the Data::FormValidator::Results
94           object.  The meta data added is "width" and "height".
95
96       image_min_dimensions
97           This function checks to make sure an uploaded image is longer than
98           some minimum dimensions. The params are:
99
100            reference to min pixel width
101            reference to min pixel height
102
103               image_min_dimensions(100,100),
104
105           Calling this function sets some meta data which can be retrieved
106           through the "meta()" method of the Data::FormValidator::Results
107           object.  The meta data added is "width" and "height".
108
109   BACKWARDS COMPATIBILITY
110       An older more awkward interface to the constraints in this module is
111       still supported.  To use it, you have to load the package with
112       'validator_packages', and call each constraint in a hashref style,
113       passing the parameters by reference. It looks like this:
114
115           validator_packages => [qw(Data::FormValidator::Constraints::Upload)],
116           constraints => {
117               image_name => [
118                   {
119                       constraint_method => 'image_max_dimensions',
120                       params => [\200,\200],
121                   }
122                ],
123           }
124
125       I told you it was more awkward. That was before I grokked the magic of
126       closures, which is what drives the current interface.
127

SEE ALSO

129       FileMetadata, Data::FormValidator, CGI, perl
130

AUTHOR

132       Mark Stosberg, <mark@summersault.com>
133
135       Copyright 2003-2005 by Mark Stosberg
136
137       This library is free software; you can redistribute it and/or modify it
138       under the same terms as Perl itself.
139
140
141
142perl v5.28.0                      20D1a7t-a0:8:-F2o8rmValidator::Constraints::Upload(3)
Impressum