note 99746 added to function.mssql-query
| From: | alpa at 33oxclove dot com | Date: | Thu, 02 Sep 2010 16:06:34 +0000 |
| Subject: | note 99746 added to function.mssql-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-172280@lists.php.net to get a copy of this message | ||
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.
$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: 216.73.250.135
----
Manual Page -- http://www.php.net/manual/en/function.mssql-query.php
Edit -- https://master.php.net/note/edit/99746
Del: integrated -- https://master.php.net/note/delete/99746/integrated
Del: useless -- https://master.php.net/note/delete/99746/useless
Del: bad code -- https://master.php.net/note/delete/99746/bad+code
Del: spam -- https://master.php.net/note/delete/99746/spam
Del: non-english -- https://master.php.net/note/delete/99746/non-english
Del: in docs -- https://master.php.net/note/delete/99746/in+docs
Del: other reasons-- https://master.php.net/note/delete/99746
Reject -- https://master.php.net/note/reject/99746
Search -- https://master.php.net/manage/user-notes.php