在smyfony2中上传html文件

时间:2016-02-16 14:17:42

标签: file symfony

我想使用symfony上传一个html文件,但总是收到错误

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

我班级文件的代码如下:

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 

任何帮助,请

1 个答案:

答案 0 :(得分:1)

由于您说它适用于*.psd*.csv,但不适用于*.html,可能只是因为@Assert\File注释允许mimetypes { {1}}和psd但不允许csv个文件。

HTML文件应由html mimetype标识,因此请尝试将text/html添加到text/html中允许的mime类型列表中,看看是否有帮助。