2016-02-16 48 views
0

我要上传一个HTML文件中使用symfony的,但我总是得到一个错误将HTML文件上传

Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed 

我班docuement的代码是作为遵循

class document 
{ 

    /* ... */ 

    private $id; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="filename", type="string", length=255, nullable=true) 
    */ 
    private $filename; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="realfilename", type="string", length=255, nullable=true) 
    */ 
    private $realfilename; 

    /** 
    * @Assert\File(
    * maxSize = "5000k", 
    * mimeTypes = {"text/comma-separated-values", "application/pdf", "text/csv", "application/csv", "application/excel", "application/vnd.ms-excel", "application/vnd.msexcel", "application/octet-stream","text/plain"}, 
    *) 
    */ 
    private $file 

    /* ... */ 
} 

的功能可以做的序列化是

$serialize = serialize($docuement); 
$encodingDoc = $serviceUtils->encode($serialize, $this->container->getParameter('key_encrypt')); 

当我上传一个pdf文件ou cvs文件,一切工作很好,但是当我尝试上传HTML文件,我得到一个错误

Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed 

任何帮助,请

+2

我们需要在这里发布您的代码,否则我们无法帮助您。 – martin

+0

用我的代码修改 –

回答

1

既然你说这工作得很好用*.psd*.csv但不与*.html工作,可能只是因为@Assert\File注释允许的mimetypes为psdcsv,但不允许html文件。

HTML文件应该标识为text/html mimetype,因此请尝试将text/html添加到@Assert\File中的允许MIME类型列表中,并查看是否有帮助。

+0

问题是调用序列化函数时 –