0

I have images stored in mssql database . I want to retrieve the data via php and create image file . I have tried numerous possibilities but unable to find any correct solution

Image i have in following format stored in database

0xFFD8FFE000104A46494600010200000100010000FFDB00840001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010

I have tried

$row = mssql_fetch_assoc($result);
 $db_img = $row['imgdata'];
$db_img = pack("H" . strlen($db_img), $db_img);
header("Content-Type: image/jpeg");
echo $db_img;

displays black image

Also i have tried

file_put_contents( 'test_image.jpg', $binary_data); 

Not Working ....

Also tried ...

imagecreatefromstring("0xFFD8FFE000104A46494600010200000100010000FFDB00840001010101010101010101010101010101010101010101010101010101010101010101010101.........");

enter image description here

Abdul Basit
  • 493
  • 11
  • 34
  • Possible duplicate of [How can I store and retrieve images from a MySQL database using PHP?](http://stackoverflow.com/questions/1636877/how-can-i-store-and-retrieve-images-from-a-mysql-database-using-php) – devlin carnate May 20 '16 at 15:39
  • As i Said i have already tried that solution it doesnt work for me and the duplicate you quote he is saving image in database and i want to create an image file from mssql server data type image – Abdul Basit May 20 '16 at 15:44
  • It not only shows how to store an image, but how to retrieve it as well. Nothing in your question shows that you've tried that solution. – devlin carnate May 20 '16 at 15:47
  • Omg this question has nothing to do with mine....i need create image from binary string not database and string is Image Type in mssql and i want to create a file from it while he is just displaying the image ....and you gave me -1 – Abdul Basit May 20 '16 at 15:53
  • @AbdulBasit what is the data type of imgdata in the database? – muglio May 20 '16 at 21:30

0 Answers0