Display pdf blob file from database

后端 未结 3 979
遇见更好的自我
遇见更好的自我 2021-01-13 04:26

I have stored pdf file into database i.e blob type. Now I wanna display pdf like

$sqll=\"select * from pdff\";
$query=mysql_query($sqll) or die(mysql_error()         


        
3条回答
  •  隐瞒了意图╮
    2021-01-13 05:26

    I know this thread is old but I recently had a similar issue to solve and wrote this quick guide to cover it. https://medium.com/@alexmoran_19787/display-pdf-from-blob-file-11996146dbc0

    Basically Depending on if you addslashes or not when inputing the pdf into the database you can view it by the following I had this in my controller and passed the info to a php page. Setting the headers and if you addslashes make sure to stripslashes otherwise you will just end up with the raw data or blank screen.

        $content = stripslashes($text["file"]);
        header('Content-type: application/pdf');
        header('Content-Disposition: inline; filename=document.pdf');
        header('Content-Transfer-Encoding: binary');
        header('Accept-Ranges: bytes');
        
        $this->load->view("administrator/load_pdf", [
            "title"=>"Display PDF",
            "pdf"=>$content,
        ]);
    

    This is from the php page.

      
    

提交回复
热议问题