{
    "mode": "perldoc",
    "parameter": "Data::FormValidator::Constraints::Upload",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Data%3A%3AFormValidator%3A%3AConstraints%3A%3AUpload/json",
    "generated": "2026-09-24T20:39:27Z",
    "synopsis": "# Be sure to use a CGI.pm or CGI::Simple object as the form\n# input when using this constraint\nmy $q = CGI->new;\nuse Data::FormValidator::Constraints::Upload qw(\nfileformat\nfilemaxbytes\nimagemaxdimensions\nimagemindimensions\n);\nmy $dfv = Data::FormValidator->check($q,$myprofile);\n# In a Data::FormValidator Profile:\nconstraintmethods => {\nimagename => [\nfileformat(),\nfilemaxbytes(10),\nimagemaxdimensions(200,200),\nimagemindimensions(100,100),\n],\n}",
    "sections": {
        "NAME": {
            "content": "Data::FormValidator::Constraints::Upload - Validate File Uploads\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "# Be sure to use a CGI.pm or CGI::Simple object as the form\n# input when using this constraint\nmy $q = CGI->new;\n\nuse Data::FormValidator::Constraints::Upload qw(\nfileformat\nfilemaxbytes\nimagemaxdimensions\nimagemindimensions\n);\nmy $dfv = Data::FormValidator->check($q,$myprofile);\n\n# In a Data::FormValidator Profile:\nconstraintmethods => {\nimagename => [\nfileformat(),\nfilemaxbytes(10),\nimagemaxdimensions(200,200),\nimagemindimensions(100,100),\n],\n}\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Note: This is a new module is a new addition to Data::FormValidator and is should be considered\n\"Beta\".\n\nThese module is meant to be used in conjunction with the Data::FormValidator module to automate\nthe task of validating uploaded files. The following validation routines are supplied.\n\nTo use any of them, the input data passed to Data::FormValidator must be a CGI.pm object.\n\nfileformat\nThis function checks the format of the file, based on the MIME type if it's available, and a\ncase-insensitive version of the file extension otherwise. By default, it tries to validate\nJPEG, GIF and PNG images. The params are:\n\noptional hash reference of parameters. A key named I<mimetypes> points to\narray references of valid values.\n\nfileformat( mimetypes => [qw!image/jpeg image/gif image/png!] );\n\nCalling this function sets some meta data which can be retrieved through the meta() method\nof the Data::FormValidator::Results object. The meta data added is \"extension\" and\n\"mimetype\".\n\nThe MIME type of the file will first be tried to figured out by using the <File::MMagic>\nmodule to examine the file. If that doesn't turn up a result, we'll use a MIME type from the\nbrowser if one has been provided. Otherwise, we give up. The extension we return is based on\nthe MIME type we found, rather than trusting the one that was uploaded.\n\nNOTE: if we have to fall back to using the MIME type provided by the browser, we access it\nfrom the original *input* data and not the *filtered* data. This should only cause issue\nwhen you have used a filter to alter the type of file that was uploaded (e.g. image\nconversion).\n\nfilemaxbytes\nThis function checks the maximum size of an uploaded file. By default, it checks to make\nsure files are smaller than 1 Meg. The params are:\n\nreference to max file size in bytes\n\nfilemaxbytes(1024), # 1 k\n\nCalling this function sets some meta data which can be retrieved through the meta() method\nof the Data::FormValidator::Results object. The meta data added is \"bytes\".\n\nimagemaxdimensions\nThis function checks to make sure an uploaded image is no longer than some maximum\ndimensions. The params are:\n\nreference to max pixel width\nreference to max pixel height\n\nimagemaxdimensions(200,200),\n\nCalling this function sets some meta data which can be retrieved through the meta() method\nof the Data::FormValidator::Results object. The meta data added is \"width\" and \"height\".\n\nimagemindimensions\nThis function checks to make sure an uploaded image is longer than some minimum dimensions.\nThe params are:\n\nreference to min pixel width\nreference to min pixel height\n\nimagemindimensions(100,100),\n\nCalling this function sets some meta data which can be retrieved through the meta() method\nof the Data::FormValidator::Results object. The meta data added is \"width\" and \"height\".\n\nBACKWARDS COMPATIBILITY\nAn older more awkward interface to the constraints in this module is still supported. To use it,\nyou have to load the package with 'validatorpackages', and call each constraint in a hashref\nstyle, passing the parameters by reference. It looks like this:\n\nvalidatorpackages => [qw(Data::FormValidator::Constraints::Upload)],\nconstraints => {\nimagename => [\n{\nconstraintmethod => 'imagemaxdimensions',\nparams => [\\200,\\200],\n}\n],\n}\n\nI told you it was more awkward. That was before I grokked the magic of closures, which is what\ndrives the current interface.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "FileMetadata, Data::FormValidator, CGI, perl\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Mark Stosberg, <mark@summersault.com>\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "Copyright 2003-2005 by Mark Stosberg\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        }
    },
    "summary": "Data::FormValidator::Constraints::Upload - Validate File Uploads",
    "flags": [],
    "examples": [],
    "see_also": []
}