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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度