I've been pulling my hair out for a couple of days about the issue i'm having.
Trying to read a PDF that is stored as binary blob data in a SQL database (not mysql) varbinary field.
If I use a program like Navicat, and save the raw blob data directly as a PDF, the file works.
When I try and read the data through PHP from a mssql query and create a PDF file -
$file = "file.pdf";
$data = $row['FileData'];
file_put_contents($file, $data);
It creates the PDF, however it is corrupt and will not open.
I have difficulty in knowing exactly what format the data is stored as in the database. When I view the BLOB data in Navicat, it renders it like this:
%PDF-1.4
%Çì¢
5 0 obj
<</Length 6 0 R/Filter /FlateDecode>>
stream
xœÅY[o·F_÷Wð%èlðÞûX¸-8èCÐy-Éjt±´qÚüŒö÷#‡Crv¹Y§ÞÔ`qÈÃÃsùÎ…Ô“# ±ñglïW_çÄÍn•¦ÅwɃç›ÕÓÊ*þKíx{/þxAR‹‹ë•CZN\I8ŠßF8FcI\ܯ†ß/þ±b3jlx?â? ¶rÔÊ‚áÅÛ¼}3Ïm2£y¡·ÿO«WÐB
'ÉŽÖ‰û•Æ—Ï»é[¢¸$”•ViGÅ^<_®¿\Ù‘øçÊ‹oAûÍj£a\’¡ÙBÉÞ¿´q×ë$TÆqRúI<–3weÆúežwÕ
9q–a›¢W¯~¢«ÕHŒ^£l\Ìÿê7–‹H^–
It's hard to show you what the raw data in the database looks like, as binary data as I believe can't be viewed properly, and what you see is just the interpretation of what it really is.
Any help would be appreciated. Thank you.