在cakephp中下载Blob文件

时间:2011-03-18 20:13:17

标签: mysql cakephp http-headers blob

我正在使用此查询将图像保存在mysql中的中间blob中,该版本调用品牌控制器中的下载功能

SELECT *,CONCAT(\"<img src='../../brands/download/?file_id=\",id,
                        \"&name=\",logo_name,\"'/>\") AS file
                         FROM c_brands WHERE merchant_id=" .$merchant_session;

DOWN LOAD FUNCTION

function download()
    {
        //$this->view = 'Media';
        Configure::write('debug', 1);
        $id = $_GET["file_id"];
        $file = $this->Brand->findById($id);        

        header('Content-type: ' . $file['Brand']['logo_type']);
        header('Content-length: ' . $file['Brand']['logo_size']);
        header('Content-Disposition: inline; filename='.$file['Brand']['logo_name']);
        echo $file['Brand']['logo'];
        exit();
    }

但不知何故,它只是显示图像的占位符。

1 个答案:

答案 0 :(得分:1)

你能解释一下吗?我的意思是,第一个查询(带有Concat的查询)和download()操作之间的关系是什么,再加上你如何使用这个查询?另外,我注意到你正在放置<img src='../../brands/download/?file_id=\",并且相对路径是错误的。它必须是src="/brands/download"

但是,你的问题还不清楚。