【发布时间】:2017-03-31 15:21:12
【问题描述】:
我想下载我保存在我的 phpmyadmin 'blob' 中的 pdf 文件
我试试这个代码:
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();
}
我得到这个错误:
响应内容必须是字符串或对象实现 __toString(),“资源”给定。
请帮帮我
先谢谢
【问题讨论】:
-
试试toString($pdfFile)作为响应对象的第一个参数?
-
看起来您正在获取资源。试试
\Doctrine\Common\Util\Debug::dump($item);exit;看看里面有什么。
标签: php symfony-2.5