0

I am a beginner here. I have a column type varbinary(max) with images in it and after echoing it, i get a bunch of these random figure on my site:

���*��d���=��O�

Anyone know what this means?

I'm echoing it like this from my database:

include 'DB_Connection';
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
header("Content-type: image/jpg");
echo $row['image'];
}
Allan
  • 35
  • 1
  • 7
  • possible duplicate of [I need my PHP page to show my BLOB image from mysql database](http://stackoverflow.com/questions/13225726/i-need-my-php-page-to-show-my-blob-image-from-mysql-database) – newfurniturey Jun 09 '13 at 23:46
  • Very similar, but this one involves SQL Server instead of MySQL – MaxiWheat Jun 09 '13 at 23:48
  • 1
    is there a good reason to store images in the db? rather than the file system –  Jun 09 '13 at 23:50
  • 1
    @MaxiWheat The storage engine doesn't matter in this case - the issue is with displaying it to the browser (i.e. from PHP). – newfurniturey Jun 09 '13 at 23:51
  • @Dagon Since this is my first time, i didn't know anything else and its only 10 images. – Allan Jun 09 '13 at 23:52
  • 1
    it is generally considered best to not store files in the db. Store their name\path in the db, and then put the files in the files system. –  Jun 09 '13 at 23:56
  • The number of images is irrelevant, the filesystem is designed to store files, which is how an image should be stored. You should consider switching. – Jessica Jun 09 '13 at 23:56
  • @Dagon hm, I'm thinking on doing that then.. Will there be many changes if i switch method ? – Allan Jun 10 '13 at 00:02
  • many? you know your site\code i don't. –  Jun 10 '13 at 00:06

1 Answers1

0

it's jpeg, not jpg.

However, you should store the images in the filesystem.

Also, there's absolutely no reason to have that code within a while loop. It won't do any good after the first time, you can only display one image that way.

Jessica
  • 7,075
  • 28
  • 39