Image 如何对base64_解码的图像进行编码,symfony
我有一个用base64_解码的图像。 我有一个实体图像。这是实体组成:id和文件路径。根据本指南将映像加载到服务器的文件 如何对该字符串进行编码,将文件上载到服务器,并将路径上载到控制器中的数据库 我的控制器Image 如何对base64_解码的图像进行编码,symfony,image,symfony,base64,Image,Symfony,Base64,我有一个用base64_解码的图像。 我有一个实体图像。这是实体组成:id和文件路径。根据本指南将映像加载到服务器的文件 如何对该字符串进行编码,将文件上载到服务器,并将路径上载到控制器中的数据库 我的控制器 public function updateattachmentAction() { $em = $this->getDoctrine()->getManager(); $photo = $em->getRepository('MyPluginBundle
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));
}
它应该有助于
DataUriNormalizer
标题##
还有这个
首先,我认为我可以找到图像并放入解码图像,但我不能保存图像,因为我保存了图像的路径。然后我想,也许我必须创建文件,但我不知道如何在控制器中创建文件。这可能会对您有所帮助
use Symfony\Component\Serializer\Normalizer\DataUriNormalizer;
$normalizer = new DataUriNormalizer();
$avatar = $normalizer->denormalize('data:image/gif;base64,R0lGODdhAQABAIAAAP///////ywAAAAAAQABAAACAkQBADs=', 'SplFileObject');
// $avatar is a SplFileObject with the GIF image contents
use Hshn\Base64EncodedFile\HttpFoundation\File\Base64EncodedFile;
$file = new Base64EncodedFile(base64_encode($data));
$file->getPathname(); // "/path/to/file"
$file instanceof Symfony\Component\HttpFoundation\File\File; // true