doukang8949 2013-06-29 07:33
浏览 68
已采纳

在Symfony2中上传文件时设置文件类型

So I have the file upload working well. However I need to set type of file that is allowed, where and how do I set the type of file that can be uploaded. It's supposed to be an image file, and I don't want users (obviously) uploading anything but an image. I would assume it's somewhere in validation.yml?

Thank you!

  • 写回答

1条回答 默认 最新

  • douxian9943 2013-06-29 07:41
    关注

    There are two ways, or using the file validation attribute, or the image validation attribute, this last as the accepted mime types as image/*

    The examples on the site goes as followed:

    # src/Acme/BlogBundle/Resources/config/validation.yml
    Acme\BlogBundle\Entity\Author:
        properties:
            bioFile:
                - File:
                    maxSize: 1024k
                    mimeTypes: [application/pdf, application/x-pdf]
                    mimeTypesMessage: Please upload a valid PDF
    
    # src/Acme/BlogBundle/Resources/config/validation.yml
    Acme\BlogBundle\Entity\Author
        properties:
            headshot:
                - Image:
                    minWidth: 200
                    maxWidth: 400
                    minHeight: 200
                    maxHeight: 400
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,
  • ¥15 spaceclaim模型变灰色
  • ¥15 求一份华为esight平台V300R009C00SPC200这个型号的api接口文档
  • ¥15 就很莫名其妙,本来正常的Excel,突然变成了这种一格一页
  • ¥15 字符串比较代码的漏洞
  • ¥15 欧拉系统opt目录空间使用100%
  • ¥15 ul做导航栏格式不对怎么改?