2016-02-16 50 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

問題是調用序列化函數時 –