note 99746 modified in function.mssql-query by danbrown
| From: | danbrown@php.net | Date: | Thu, 02 Sep 2010 16:19:33 +0000 |
| Subject: | note 99746 modified in function.mssql-query by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-172281@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.
<?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
--was--
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
http://php.net/manual/en/function.mssql-query.php