【发布时间】:2014-07-03 00:22:23
【问题描述】:
我有一个 base64_decode 的图像解码。 我有一个实体图像。这是实体组成:文件的 ID 和路径。通过本指南http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html将图像加载到服务器的文件。
如何对该字符串进行编码并将文件上传到服务器以及将路径上传到控制器中的数据库。
我的控制器
public function updateattachmentAction()
{
$em = $this->getDoctrine()->getManager();
$photo = $em->getRepository('MyPluginBundle:Photo')->findOneById(4);
$str="";
$request = $this->container->get('request');
$image = $request->query->get('image');
// file_put_contents($photo, base64_decode($data));
// $photo->upload();
// $em->persist($photo);
// $em->flush();
$response = array("code" => 100,"success" => true);
//you can return result as JSON
return new Response(json_encode($response));
}
【问题讨论】:
-
首先,我认为我可以找到图像并放入解码后的图像,但我无法保存图像,因为我保存了图像的路径。然后我想,也许我必须创建文件,但我不知道如何在控制器中创建文件。