note 99919 added to function.mssql-query
| From: | freddy at osu1 dot php dot net | Date: | Wed, 15 Sep 2010 00:21:30 +0000 |
| Subject: | note 99919 added to function.mssql-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-172566@lists.php.net to get a copy of this message | ||
hi, im storing pdf files in an sql database as per below. The store seems to work fine, however I
am trying to retrieve and download or display the file from the sql data and it fails as a corrupt
pdf file
to retrieve i am just selecting from the database, changing content type and echoing data - eg
below.
Any ideas why this wouldnt work>?
header("Content-Disposition:attachment;filename=$filename");
echo $data;
Hi All,
I was trying to insert PDF in MSSQL image datatype and had a worst time figuring out how to add PDF
without encoding it with base64_encode. Encoding/decoding works best but it was conflicting with
other existing PDFs in database as they weren't encoded.
The solution is to create hex string and the Trick is *NOT* to use quotes in query.
<?php
$FileName = $_FILES['pdffile']['tmp_name'];
$dataString = file_get_contents($FileName );
$arrData = unpack("H*hex", $dataString);
$hexdata = "0x".$arrData['hex'];
?>
Query:
$sql = "insert into docs(pdfname, pdfdoc) values('$pdfname', $hexdata)
Hope this helps to someone.... Cheerzz
----
Server IP: 69.147.83.197
Probable Submitter: 218.185.32.47
----
Manual Page -- http://www.php.net/manual/en/function.mssql-query.php
Edit -- https://master.php.net/note/edit/99919
Del: integrated -- https://master.php.net/note/delete/99919/integrated
Del: useless -- https://master.php.net/note/delete/99919/useless
Del: bad code -- https://master.php.net/note/delete/99919/bad+code
Del: spam -- https://master.php.net/note/delete/99919/spam
Del: non-english -- https://master.php.net/note/delete/99919/non-english
Del: in docs -- https://master.php.net/note/delete/99919/in+docs
Del: other reasons-- https://master.php.net/note/delete/99919
Reject -- https://master.php.net/note/reject/99919
Search -- https://master.php.net/manage/user-notes.php