Skip to content
Advertisement

Can’t display medium size pdf blob from database

I’m trying to display my PDFs stored in a MariaDB database on my XAMPP server via HTML and PHP

Code:

<object data="data:application/pdf;base64,<?php echo base64_encode($this->view_data[0]["test"]); ?>" type="application/pdf" style="height:100%;width:100%"></object>

It works for PDFs with a size of 500kB but for PDFs with the larger size, the Page stays blank.

Is there any configuration I have to do in my XAMPP conf files? I tried to increase pretty much all of them nothing seems to work
Edit: I’m using "SELECT test from PDF WHERE testID = 1" with the function

public function dbQuery($query, $params = []){ $stmt = $this->connect()->prepare($query); $stmt->execute($params); if (explode(' ',$query)[0] == "SELECT"){ $result = $stmt->fetchAll(); $this->close($this); return $result; } else{ $this->close($this); return $stmt->fetchAll(); } $this->close($this); }

to populate the var $this->view_data so the PDF is stored in $this->view_data[0][“test”]

It works fine for everything blobsize <= 500kB. I tried setting the PDO MYSQL_ATTR_MAX_BUFFER_SIZE but the variable is not even initialized.

Advertisement

Answer

I found the answer. It was because I didn’t use PDOs statements for LOBs (large objects) With

    $db = new PDO("mysql:host=".$dbhost.";dbname=".$dbname.";charset=utf8",$dbuser, $dbpwd);
    $stmt = $db->prepare("SELECT test FROM PDFs WHERE testID=?");
    $stmt->execute(array($_GET['testID']));
    $stmt->bindColumn(1, $lob, PDO::PARAM_LOB);
    $stmt->fetch(PDO::FETCH_BOUND);

header("Content-Type: application/pdf");
fpassthru($lob);

It works.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement