I am trying to download a file from postgresql encoded in base 64. The content of the file seems to be good in the database bytea
but it is not the same when I download it with PHP:
I am using PHP 5.6 with symfony 2.8. I've tried to decode in base 64 but with no success.
$name = $file->getName();
$content = base64_decode(stream_get_contents($file->getContent()));
$contentType = $file->getContentType();
$response = new Response();
$response->headers->set("Cache-Control", "no-cache private");
$response->headers->set("Content-Description", "File Transfer");
$response->headers->set('Content-Type', $contentType);
$response->headers->set('Content-Disposition', 'attachment; filename="' . $name . '"');
$response->headers->set("Content-Transfer-Encoding", "binary");
$response->headers->set('Content-Length: ', strlen($content));
$response->sendHeaders();
$response->setContent($content);
return $response;
For this example, I've created a file with notepad++ containing the string "test
". In the database it is displayed like this "dGVzdA==
".
When I download the file and I decode it, the content is this "Ǯ8kθطw
", it should be "test
".