I
I
Ilya Saligzhanov2019-07-24 10:03:12
PHP
Ilya Saligzhanov, 2019-07-24 10:03:12

How to count BLOB from PostgreSQL via PDO?

There is a base, record format:
record id || sha1 || BLOB content || name || size || user id
Attempt to execute code:

$query = 'SELECT * FROM "table_name" WHERE "fUserId"=:userid';
$result = $DB -> prepare($query);
$result -> execute(array(
    ':userid' => $_REQUEST['userId']
));
$result -> bindColumn(3, $file['fContent'], PDO::PARAM_LOB);
$result -> bindColumn(4, $file['fName'], PDO::PARAM_STR);
$result -> bindColumn(5, $file['fSize'], PDO::PARAM_INT);
$result -> fetch(PDO::FETCH_BOUND);

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $file['fName']);
header('Content-Transfer-Encoding: "binary"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . $file['fSize']);

fpassthru($file['fContent']);

It ends with a file with the content of the form: "x255044462d312e340a25e2e3cfd30a37392030206f626a0a3c3c2f445" - i.e. the binary is given in
hex, and then character-by-character into a string. What specific header/headers prevent the file from being rendered in a normal .pdf format?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Saligzhanov, 2019-07-24
@Le_Traceur_Snork

Found the answer.
The solution was to make
Before starting SELECT

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question