首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laminas\InputFilter\FileInput到底做了什么?

Laminas\InputFilter\FileInput到底做了什么?
EN

Stack Overflow用户
提问于 2021-01-26 00:52:21
回答 1查看 71关注 0票数 0

我一直在为他们的FIleInput类研究Laminas documentation,但我还没有找到一个合适的解释来解释这些过滤器和验证器到底是做什么的。

我正在建立一个社区网站,并计划让用户上传文件,我想对这些上传的文件应用安全检查,我对此进行了很多研究,我计划在StackOverflow (herehere)的许多线程中发现图像安全检查,但我想对非图像上传的文件做一些其他检查/验证。

那么Laminas\InputFilter\FileInput真的能做到这一点吗?或者它到底是做什么的?

EN

回答 1

Stack Overflow用户

发布于 2021-08-19 12:59:39

您可以确保用户使用以下内容发送正确的文件镜像:

代码语言:javascript
复制
    public function addInputFilter()
    {
        $inputFilter = new InputFilter\InputFilter();

        // File Input
        $fileInput = new InputFilter\FileInput('image-file');
        $fileInput->setRequired(true);

        // Define validators and filters as if only one file was being uploaded.
        // All files will be run through the same validators and filters
        // automatically.
        $fileInput->getValidatorChain()
            ->attachByName('filesize',      ['max' => 204800])
            ->attachByName('filemimetype',  ['mimeType' => 'image/png,image/x-png'])
            ->attachByName('fileimagesize', ['maxWidth' => 100, 'maxHeight' => 100]);

        // All files will be renamed, e.g.:
        //   ./data/tmpuploads/avatar_4b3403665fea6.png,
        //   ./data/tmpuploads/avatar_5c45147660fb7.png
        $fileInput->getFilterChain()->attachByName(
            'filerenameupload',
            [
                'target'    => './data/tmpuploads/avatar.png',
                'randomize' => true,
            ]
        );
        $inputFilter->add($fileInput);

        $this->setInputFilter($inputFilter);
    }

以下是输入筛选器的列表:

  • Count
  • crc32
  • ExcludeExtension
  • ExcludeMimeType
  • Exists
  • Extension
  • FilesSize
  • Hash
  • ImageSize
  • IsCompressed
  • IsImage
  • Md5
  • MimeType
  • NotExists
  • Sha1
  • Size
  • Upload
  • UploadFile
  • WordCount

文档:https://docs.laminas.dev/laminas-validator/validators/file/intro/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65889019

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档