我想下载我的pdf文件,并将其保存在我的phpmyadmin'blob'
中我试试这段代码:
public function downloadAction()
{
$ma_base_de_donne = new myprojectdbEntity();
$item = $this->getDoctrine()->getRepository('myprojectBundle:myprojectdbEntity')->find(5);
if (!$item) {
throw $this->createNotFoundException("File with ID 5 does not exist!");
}
$pdfFile = $item->getFichier(); //returns pdf file stored as mysql blob
//$headers = array('Content-Type' => 'application/pdf', 'Content-Disposition' => "attachment; filename=" . urlencode($pdfFile));
$response = new Response($pdfFile, 200, array('Content-Type' => 'application/pdf'));
//return $response;
var_dump($response); die();
}
我收到此错误:
请帮助我Response内容必须是字符串或对象实现 __toString(),“资源”给出。
首先感谢
答案 0 :(得分:0)
在实体对象中定义__toString()方法($ pdfFile):
public function __toString() {
return $name;
}
或直接发送回复中的字符串:
$response = new Response($pdfFile->getName(), 200, array('Content-Type' => 'application/pdf'));