Hi All,
I have the following code that essentially stores and retrieves a file from a MSSQL db. The jpeg that is being stored in the db column is of the correct type e.g. IMAGE (mysql eqv of BLOB). Code Below:
For Storing:
$datastring = file_get_contents("someimage.JPG");
$data = unpack("H*hex", $datastring);
mssql_query("insert into sometable values ('someimage.JPG', 0x".$data['hex'].")");
For Retrieving:
$result = mssql_query("select someimages from sometables where somename like 'someimage'");
$row = mssql_fetch_row($result);
header("Content-type:image/jpeg;");
echo $row[0];
The problem occurs when I try to retrieve the image, i get the following error from the browser (not php).
The image “someimage” cannot be displayed, because it contains errors.
I can only assume the hex becomes corrupted, any help would be greatly appreciated.
Thank in adavnce D