How to insert a image in a table. wat is the dimension to be mentioned?
Insert image in sql table and what is its dimension
Collapse
X
-
sajithamolTags: None -
Create a table with BLOB field, a sample table can be this
Then read the image file, encode and store in the BLOB field as in the example below.Code:CREATE TABLE `images` ( `id` int(11) NOT NULL auto_increment, `image` blob NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM;
[PHP]$image = chunk_split(bas e64_encode(file _get_contents(" image.jpg")));
$qry = "INSERT INTO images (image) VALUES('$image' )";
mysql_query($qr y) or die(mysql_error ());[/PHP]
And to display the image, use this code
[PHP]header('Content-type: image/jpeg');
$rs = mysql_fetch_arr ay(mysql_query( "SELECT image from images where id=1"));
echo base64_decode($ rs["image"]);[/PHP]
But make sure there must not be any sort of output before header().
Why you want to store the images in the DB?
Comment