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 华为ensp使用基本ACL限制公司网络访问
  • ¥15 帮我做下照片上的PLC题
  • ¥15 labview2022 使用modbus报缺少依赖?
  • ¥15 谷歌地图是不是不开通结算功能,api会使用不了哦
  • ¥15 unity腾讯云对象存储机型适配
  • ¥15 求全国交通咨询模拟代码,要求如下,可以完全在dev c++运行
  • ¥15 根据要求修改程序编码
  • ¥15 用 Python 做一个用 Excel 表导入的答题系统
  • ¥15 使用微信开发者工具实现一个“婚博会”小程序
  • ¥15 ros的rviz仿真机器人