我想限制用户上传。我想提供仅上传pdf格式。我这样做是为了我的领域:
/**
* @Assert\File(maxSize="6M", mimeTypes={"pdf"})
*/
private $document;
但这没有用。我做错了什么?
答案 0 :(得分:0)
正确的pdf mime类型为application/pdf
- look at this
/**
* @Assert\File(maxSize="6M", mimeTypes={"application/pdf"})
*/
private $document;
查看official documentation注释部分,也许你遗漏了一些东西
//simple example
namespace Your\Bundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
//test class
class YourClass
{
/**
* @Assert\File(
* maxSize = "6M",
* mimeTypes = {"application/pdf", "application/x-pdf"},
* mimeTypesMessage = "Please upload a valid PDF"
* )
*/
protected $document;
}