Welcome Guest, Not a member yet? Register   Sign In
PDF stored in mssql
#1

I have a database that is on a sqlsrv. I have managed to connect to it CI and I can retrieve the data.

All that works very well indeed. My problem is with a PDF that is stored in a varbinay filed.
I can access the field and I get the data, but somehow the data seems to short. Something seems missing.

I use file_put_contents to save the data as an external file but when I open it I get an error message that the PDF is corrupt and cannot be repaired.

this is the sql from the model that I use

SELECT f.stid,  f.fieldpcl
FROM SightTest.fieldspcl AS f                   
INNER JOIN customer.customers AS c ON c.customerid = f.customerid
WHERE c.customerid IN ('$id')                   
                   


and this is the code

$data['fieldspcl'] = $this->vera_model->getFieldspcl($id);

        if ( ! empty ($data['fieldspcl'])){
            //create physical files
            $filename = $this->config->item('root_folder') . "/pdf/{$id}-{$data['fieldspcl']->stid}.pdf";
            $data['fieldspcl']->filename = $this->config->item('base_url'). "/pdf/{$id}-{$data['fieldspcl']->stid}.pdf";
            file_put_contents($filename, $data['fieldspcl']->fieldpcl);
        }

When I look at the PDF and a PDF that works I see that for example %%EOF is missing at the end. But even adding that did not help

Any help would be creatly appriciated.
On the package it said needs Windows 7 or better. So I installed Linux.
Reply
#2

Perhaps the data being truncated? If the column is a standard varbinary then, unless I'm mistaken, the max size is 8000 bytes. A datatype of varbinary(max) allows ~2GB of data.

If size isn't the issue the you might try the PHP functions serialize() before storing and unserialize() on reading from the db.
Reply
#3

Well, I've run into something similar to this before. I don't actually know why sqlsrv sometimes that bad in storing files in there, but you won't extract it with no additional software, that's for sure. I suggest you something like this https://www.altoextractpdf.com I hadn't tested it with a great number of things but have had with databases and it worked out fine in all cases. Do hope you're still following this thread, so it will come in use to you
Reply




Theme © iAndrew 2016 - Forum software by © MyBB