[html-formfu] new file upload constraints

Вячеслав Тихановский viacheslav.t at gmail.com
Fri Jan 18 23:06:44 GMT 2008


2008/1/18, Carl Franks <fireartist at gmail.com>:
> In svn , there's now a File::Size constraint, with min() and max() methods.
> You can set either or both methods.
> These check against the browser-submitted Content-Length (byte count).
>
>     constraints:
>       name: file
>       type: File::Size
>       min: 1
>       max: 10_000_000
>
> There's a File::MIME constraint with types() and regex() methods.
> types() accepts either a single MIME-type, or an array-ref of MIME-types.
> If none of these exactly match the browser-submitted Content-Type (or
> types() wasn't set), then regex() is matched against it.
> The regex uses the '\x' flag, so whitespace is ignored.
>
>     constraints:
>       name: file
>       type: File::MIME
>       regex: '^ image / (?: jpeg | png ) \z'
>
>
> There's also a 'File' constraint, to ensure a file was uploaded, but
> this is unnecessary if any of the File::* constraints are used, as
> they all do the same test anyway.
> Read the "limitations" section in it's docs, if you plan on using it.
>
> Carl
>
> _______________________________________________
> HTML-FormFu mailing list
> HTML-FormFu at lists.rawmode.org
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>

I guess it should be like this? =)

Index: HTML/FormFu/Constraint/File/MIME.pm
===================================================================
--- HTML/FormFu/Constraint/File/MIME.pm (revision 787)
+++ HTML/FormFu/Constraint/File/MIME.pm (working copy)
@@ -25,7 +25,7 @@
     }

     if ( defined $regex ) {
-        return $input =~ /$input/x;
+        return $input =~ /$regex/x;
     }

     return;



More information about the HTML-FormFu mailing list