我正在尝试将.docx
文件存储到mysql数据库中。我知道.docx
个文件实际上是.zip
个文件。但是,我正在尝试将它们存储到blob字段中,因此应该有任何区别。
如果我尝试存储的文件不是.docx
,请说.png, .jpeg, .pdf
。一切正常,但是当我尝试存储.docx
文件时,我得到500作为响应,没有错误消息。
这是我的代码:
public function saveResumee($slug, $file)
{
$em = $this->getEntityManager();
$resumee = new File(file_get_contents($file), $file->getMimeType(), $file->guessExtension(), $file->getClientSize());
$em->persist($resumee);
$em->flush(); // Everything blows up here!
...
return true;
}
这是我的File
实体
<?php
namespace DnD\RaHApiBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* File
*
* @ORM\Table()
* @ORM\Entity
*/
class File
{
public function __construct($data, $type, $extension, $length)
{
$this->data = $data;
$this->type = $type;
$this->extension = $extension;
if ($length) $this->length = $length;
}
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="data", type="blob")
*/
private $data;
/**
* @var string
*
* @ORM\Column(name="extension", type="string", length=255)
*/
private $extension;
/**
* @var integer
*
* @ORM\Column(name="length", type="integer")
*/
private $length;
/**
* @var string
*
* @ORM\Column(name="type", type="string", length=16)
*/
private $type;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set data
*
* @param string $data
* @return File
*/
public function setData($data)
{
$this->data = $data;
return $this;
}
/**
* Get data
*
* @return string
*/
public function getData()
{
return $this->data;
}
/**
* Set length
*
* @param integer $length
* @return File
*/
public function setLength($length)
{
$this->length = $length;
return $this;
}
/**
* Get length
*
* @return integer
*/
public function getLength()
{
return $this->length;
}
/**
* Set type
*
* @param string $type
* @return File
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* Get type
*
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* @return string
*/
public function getExtension()
{
return $this->extension;
}
/**
* @param string $extension
*/
public function setExtension($extension)
{
$this->extension = $extension;
}
}
这有什么问题?